Hiding
Peter Hansen
peter at engcorp.com
Fri Jul 29 17:08:01 EDT 2005
Jason Drew wrote:
> Also, I think
> using file("C:\file.txt") is now preferred to open("C:\file.txt").
As others have noted, "open" is preferred as the method for opening
files, while "file" is the _type_ involved, for testing or subclassing
or what-have-you.
But neither file("C:\file.txt") nor open("C:\file.txt") is actually
correct at all, unless you have strange files whose names start with
ASCII FF characters. '\f' is an escape sequence, equivalent to '\x0c'.
Always use forward slashes ("C:/file.txt") in path names unless you are
passing them to the shell, or use raw strings (r"C:\file.txt") to avoid
mysterious problems with escape sequences.
-Peter
More information about the Python-list
mailing list