Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: File operations

Gary Herron
Guest
 
Posts: n/a
#1: Aug 22 '08
aditya shukla wrote:
Quote:
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(search_file,"rb")


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

John Machin
Guest
 
Posts: n/a
#2: Aug 22 '08

re: Re: File operations


On Aug 22, 9:33 am, Gary Herron <gher...@islandtraining.comwrote:
Quote:
aditya shukla wrote:
Quote:
Hello guys
>
Quote:
I am trying to search a file say xyz.txt
>
Quote:
after searching i get the location of the file in
>
Quote:
search_file (containing abspath) ,eg search_file="c:\\abc\\xyz.txt"
>
Quote:
now how should i open this file
>
Quote:
i can use file=open("c:\\abc\\xyz.txt","rb") but i have to use search_
file
>
file=open(search_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"

Fredrik Lundh
Guest
 
Posts: n/a
#3: Aug 22 '08

re: Re: File operations


John Machin wrote:
Quote:
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>

Closed Thread


Similar Python bytes