Python 2.4 and os.open question?

Eino Mäkitalo eino at iki.fi
Tue Jan 11 15:45:03 CET 2005


I just test in Windows XP with Python 2.4

I'd like to create a file with exclusive flag.
If file exist I try to use it, if not I'd like to create it.
Python (and underlying library) works differently with/without O_EXCL 
flag. Is this okay. How I should use this.

Has somebody manual :-) ?

Eino Mäkitalo

see scenarios (1 without flag ) (2 with flag)

Scenario 1:

To create file if it's not available this works ok

 >>> aa=os.open("c:\\temp\\a.txt",os.O_RDWR|os.O_CREAT)
 >>> os.close(aa)
 >>> aa=os.open("c:\\temp\\a.txt",os.O_RDWR|os.O_CREAT)
 >>> os.close(aa)


Scenario 2:
But if you try to do same with O_EXCL then it does not use same logic???

 >>> aa=os.open("c:\\temp\\a.txt",os.O_RDWR|os.O_EXCL|os.O_CREAT)
 >>> os.close(aa)
 >>> aa=os.open("c:\\temp\\a.txt",os.O_RDWR|os.O_CREAT)
Traceback (most recent call last):
   File "<string>", line 1, in <string>
OSError: [Errno 17] File exists: 'c:\\temp\\a.txt'



More information about the Python-list mailing list