[Tutor] Re: Window pathnames

Andrei project5 at redrival.net
Fri Oct 3 06:19:31 EDT 2003


Gerrit Holl wrote:
> <quote name="Zandbergen Christian" date="1065179399" email="Christian.Zandbergen at swisslife.ch">
> 
>>and the following Error occures:
>>
>>	Python 2.1.3 (#35, Apr  8 2002, 17:47:50) [MSC 32 bit (Intel)] on
>>win32
>>	Type "copyright", "credits" or "license" for more information.
>>	>>> open("C:\\dslfjsl\jlsfjslfsj")
>>	Traceback (most recent call last):
>>	  File "<stdin>", line 1, in ?
>>	IOError: [Errno 2] No such file or directory:
>>'C:\\dslfjsl\\jlsfjslfsj'
>>
>>
>>It seems that one backslash always returns a double backslash.
> 
> </quote>
> 
> Have you tried to prepend the string with 'r' (e.g. r'C:\aaa\bbb')?

Raw strings in path are not the best idea: if the path happens to end with "\", 
you may not notice it in your editor, but you'll get a syntax error because the 
backslash escapes the end quote. Especially a problem if you don't code the path 
yourself, but it's provided programmatically or by the user. I know because I 
made this error :). It would be better to just use forward slashes - works under 
Windows too.

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq gur 
yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list