Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Improvement ?

Reply
Thread Tools

Improvement ?

 
 
Jean-Marc Ranger
Guest
Posts: n/a
 
      05-05-2004
Just wondering:

With Python 2.3.3 for Windows, I understand why
os.makedirs("C:\SomeDirectoryThatDontExist\.\Anoth erDirectory") 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
 
Reply With Quote
 
 
 
 
Michael Geary
Guest
Posts: n/a
 
      05-05-2004
Jean-Marc Ranger wrote:
> With Python 2.3.3 for Windows, I understand why
> os.makedirs("C:\SomeDirectoryThatDontExist\.\Anoth erDirectory")
> 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\\.\\AnotherDire ctory")

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


Also, you got very lucky with your backslashes:

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

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

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


-Mike


 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      05-05-2004
Jean-Marc Ranger wrote:

> With Python 2.3.3 for Windows, I understand why
> os.makedirs("C:\SomeDirectoryThatDontExist\.\Anoth erDirectory") 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
 
Reply With Quote
 
Heiko Wundram
Guest
Posts: n/a
 
      05-05-2004
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.

 
Reply With Quote
 
Jean-Marc Ranger
Guest
Posts: n/a
 
      05-06-2004
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance improvement in the 2.0 framework =?Utf-8?B?TWFyYyBIb2Vpam1hbnM=?= ASP .Net 6 03-22-2006 07:48 PM
Improvement on website MaxMustermann HTML 9 07-25-2005 04:43 AM
XML performance improvement sree XML 2 04-17-2005 08:28 PM
IMHO: DataBinding for ASP.NET list controls needs improvement (VS.NET 2003) JV ASP .Net 4 03-18-2005 06:40 PM
Collections Improvement Disillusioned_01 MCSD 1 06-08-2004 03:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57