Improvement ?

Discussion in 'Python' started by Jean-Marc Ranger, May 5, 2004.

  1. Just wondering:

    With Python 2.3.3 for Windows, I understand why
    os.makedirs("C:\SomeDirectoryThatDontExist\.\AnotherDirectory") fails
    throwing an exception saying "OSError: [Errno 17] File exists" - the
    period is like a request to create the same directory a second time.

    But is this the expected behavior ? I personaly would prefer to see
    this operation succeed - and don't like the idea of writing a
    workaround :)

    Comments ?

    Thanks,

    Jean-Marc Ranger
     
    Jean-Marc Ranger, May 5, 2004
    #1
    1. Advertising

  2. Jean-Marc Ranger wrote:
    > With Python 2.3.3 for Windows, I understand why
    > os.makedirs("C:\SomeDirectoryThatDontExist\.\AnotherDirectory")
    > fails throwing an exception saying "OSError: [Errno 17] File exists" -
    > the period is like a request to create the same directory a second time.
    >
    > But is this the expected behavior ? I personaly would prefer to see
    > this operation succeed - and don't like the idea of writing a
    > workaround :)


    It feels like a bug to me. I would expect os.makedirs to run its argument
    through os.path.abspath first. But, you can easily do that yourself:

    >>> os.path.abspath("C:\\SomeDirectory\\.\\AnotherDirectory")

    'C:\\SomeDirectory\\AnotherDirectory'
    >>>


    Also, you got very lucky with your backslashes:

    >>> "C:\SomeDirectory\.\AnotherDirectory"

    'C:\\SomeDirectory\\.\\AnotherDirectory'
    >>> "C:\someDirectory\.\anotherDirectory"

    'C:\\someDirectory\\.\x07notherDirectory'
    >>>


    -Mike
     
    Michael Geary, May 5, 2004
    #2
    1. Advertising

  3. Jean-Marc Ranger

    Peter Hansen Guest

    Jean-Marc Ranger wrote:

    > With Python 2.3.3 for Windows, I understand why
    > os.makedirs("C:\SomeDirectoryThatDontExist\.\AnotherDirectory") fails
    > throwing an exception saying "OSError: [Errno 17] File exists" - the
    > period is like a request to create the same directory a second time.
    >
    > But is this the expected behavior ? I personaly would prefer to see
    > this operation succeed - and don't like the idea of writing a
    > workaround :)


    Wouldn't using os.path.normpath() on the string first be a
    really really easy workaround?

    -Peter
     
    Peter Hansen, May 5, 2004
    #3
  4. Am Mittwoch, 5. Mai 2004 21:12 schrieb Jean-Marc Ranger:
    > But is this the expected behavior ? I personaly would prefer to see
    > this operation succeed - and don't like the idea of writing a
    > workaround :)


    What you could do is pass the final directory name to os.path.abspath before
    you create it. abspath will filter out the unneccesary reference to "."
    before returning the name.

    HTH!

    Heiko.
     
    Heiko Wundram, May 5, 2004
    #4
  5. > Also, you got very lucky with your backslashes:
    >
    > >>> "C:\SomeDirectory\.\AnotherDirectory"

    > 'C:\\SomeDirectory\\.\\AnotherDirectory'
    > >>> "C:\someDirectory\.\anotherDirectory"

    > 'C:\\someDirectory\\.\x07notherDirectory'


    Oopps....

    I need to be more careful. Those names are obviously dummies, but I
    could have got stuck by that one easily.

    Thanks for spotting it.

    And thanks everyone for the hints.

    Jean-Marc
     
    Jean-Marc Ranger, May 6, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JV
    Replies:
    4
    Views:
    1,627
  2. =?Utf-8?B?TWFyYyBIb2Vpam1hbnM=?=

    Performance improvement in the 2.0 framework

    =?Utf-8?B?TWFyYyBIb2Vpam1hbnM=?=, Mar 22, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    416
    Alvin Bruney - ASP.NET MVP
    Mar 22, 2006
  3. MaxMustermann

    Improvement on website

    MaxMustermann, Jul 23, 2005, in forum: HTML
    Replies:
    9
    Views:
    375
    MaxMustermann
    Jul 25, 2005
  4. sree
    Replies:
    2
    Views:
    442
    Edward A. Feustel
    Apr 17, 2005
  5. Russell Reagan

    Improvement to C++

    Russell Reagan, Jul 2, 2003, in forum: C++
    Replies:
    1
    Views:
    359
    Victor Bazarov
    Jul 2, 2003
Loading...

Share This Page