Python doesn't see the directories I create

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Aug 30 04:53:09 EDT 2007


mr_gadget a écrit :
> When I create a subfolder, python is not seeing it. Can someone please 
> explain this behaviour ? I just started with python, read the tutorial over 
> the weekend and am writing my very first script. So I may not be seeing 
> something. Both os.path and glob.glob seem not to see a folder I created. 
> Other sibling folders seem to work fine. On a whim I tried paths with \\ 
> double slashes and that worked. But why should single slashes work for some 
> folders and not for others ??

s/slash/antislash/g

It's a very well known gotcha due to MS's choice to use the antislash as 
path separator. In most languages - Python included - the antislash is 
used for escape sequences (non-printable characters). '\r' is the escape 
sequence for CR (carriage return). Doubling the antislash prevents 
escaping.

You can avoid all escaping by using raw strings:

mypath = r"C:\enhancement\rawfiles\"

Also and IIRC, using slash instead should also work, ie:

mypath = r"C:/enhancement/rawfiles/"

HTH



More information about the Python-list mailing list