Re: File operations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Herron

    Re: File operations

    aditya shukla wrote:
    Hello guys
    >
    I am trying to search a file say xyz.txt
    >
    after searching i get the location of the file in
    >
    search_file (containing abspath) ,eg search_file="c: \\abc\\xyz.txt"
    >
    now how should i open this file
    >
    i can use file=open("c:\\ abc\\xyz.txt"," rb") but i have to use search_
    file

    file=open(searc h_file,"rb")


    >
    How can this be done?
    >
    Thanks in advance.
    >
    >
    >
    ------------------------------------------------------------------------
    >
    --
    http://mail.python.org/mailman/listinfo/python-list
  • John Machin

    #2
    Re: File operations

    On Aug 22, 9:33 am, Gary Herron <gher...@island training.comwro te:
    aditya shukla wrote:
    Hello guys
    >
    I am trying to search a file say xyz.txt
    >
    after searching i get the location of the file in
    >
    search_file (containing abspath) ,eg search_file="c: \\abc\\xyz.txt"
    >
    now how should i open this file
    >
    i can use file=open("c:\\ abc\\xyz.txt"," rb") but i have to use search_
    file
    >
    file=open(searc h_file,"rb")
    and don't use the name of the built-in file function as one of your
    own names

    and if it's really a text file, don't use "rb", use "r"

    Comment

    • Fredrik Lundh

      #3
      Re: File operations

      John Machin wrote:
      and don't use the name of the built-in file function as one of your
      own names
      "file" is a type, not a function, and has been removed in 3.0.

      given that "file" is hardly ever used in properly written Python 2 code
      (if you need to check for file-like behaviour in Python 2, check for the
      relevant attributes), assigning to "file" is a lot less problematic than
      assigning to "len" or "str" or "open" etc.

      </F>

      Comment

      Working...