Python doesn't see the directories I create

Steve Holden steve at holdenweb.com
Thu Aug 30 19:15:46 CEST 2007


Neil Cerutti wrote:
> On 2007-08-30, Bruno Desthuilliers <bruno.42.desthuilliers at wtf.websiteburo.oops.com> wrote:
>> 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). 
> 
> Keeping in mind which came first, isn't it at least as accurate
> to attribute this problem to Python's choice of escape character?
> There were probably advantages to adopting the same escape
> character as other well-known languages/codes, but the choice has
> caused some trouble over the years. 
> 
> To me, Python's collection of special-purpose string literal
> notations is one of its little warts.
> 
> Of course, I'm not smart enough to have delivered the ONE TRUE
> string literal notation either, but I do have a computer and an
> internet connection, so there you are.
> 
Well, it's a wart that's shared with many other languages - including, 
interestingly enough, Microsoft's very own C#, from whose documentation 
the following examples are taken:

string a = "hello, world";                  // hello, world
string b = @"hello, world";                 // hello, world
string c = "hello \t world";                // hello     world
string d = @"hello \t world";               // hello \t world
string e = "Joe said \"Hello\" to me";      // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me";     // Joe said "Hello" to me
string g = "\\\\server\\share\\file.txt";   // \\server\share\file.txt
string h = @"\\server\share\file.txt";      // \\server\share\file.txt
string i = "one\r\ntwo\r\nthree";

The fact is that some strings are always going to cause trouble. 
Unfortunately programming itself is a task that requires a little more 
knowledge to be applied to the task. Just learn the rules and move on.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list