What's the Scoop on \\ for Paths? (Win)
Steve Holden
steve at holdenweb.com
Sun Jan 31 13:26:16 EST 2010
W. eWatson wrote:
> I'm sure that \\ is used in some way for paths in Win Python, but I have
> not found anything after quite a search. I even have a six page pdf on a
> file tutorial. Nothing. Two books. Nothing. When I try to open a file
> along do I need, for example, "Events\\record\\year\\today"? Are paths
> like, ".\\Events" allowed, or am I mixing up my Linux memory on this?
You need to read up on string literals is all. "\\" is simply the
literal representation of a string containing a single backslash. This
comes about because string literals are allowed to contain special
"escape sequences" which are introduced by a backslash; since this gives
the backslash a special meaning in string literals we also have to use
an escape sequence ("\\") to represent a backslash.
In practice you will find that
a) Many Windows APIs (but not the command line) are just as happy with a
forward slash as a backslash to separate file path components; and
b) The best practice is to build filenames using the routines provided
in the os.path module, which guarantees to give results correct for the
current platform.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
More information about the Python-list
mailing list