What's the Scoop on \\ for Paths? (Win)
Alf P. Steinbach
alfps at start.no
Sun Jan 31 13:23:35 EST 2010
* W. eWatson:
> 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?
The Python issue with \\ is that in a literal string \\ denotes a single \
character, like
>>> print( "back\\slash" )
back\slash
>>> _
This is just like in other languages with syntax inherited from C. Look up
"escape sequences". It has nothing to do with files and paths per se, but means
that you cannot write e.g. "c:\windows\system32", but must write something like
"c:\\windows\\system32" (try to print that string), or, since Windows handles
forward slashes as well, you can write "c:/windows/system32" :-).
The Window issue with \\ is that \\ as a path prefix denotes an UNC (Universal
Naming Convention) path. Usually that would be a LAN or WAN network path, but it
can also denote a printer or a pipe or a mailslot or just about anything. Using
UNC paths opens the door to creating files and directories that other programs
won't be able to handle, so Just Say No(TM), if you can.
Cheers & hth.,
- Alf
More information about the Python-list
mailing list