472,975 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

Python 2.4 and os.open question?

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|o s.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'
Jul 18 '05 #1
2 4891
Op 2005-01-11, Eino Mäkitalo schreef <ei**@iki.fi>:
I just test in Windows XP with Python 2.4

I'd like to create a file with exclusive flag.
Why? What is it about the exclusive flag that
makes you like to use it?
If file exist I try to use it, if not I'd like to create it.
If you want that, you cant use the exclusive flag.
Python (and underlying library) works differently with/without O_EXCL
flag.
Well if the absence and presence of this flag wouldn't make a
difference, it would hardly be usefull to have such a flag,
wouldn't it?
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???
That is what flags are for: to change the logic. O_EXCL, makes sure
you are the one that creats the file. If the file exists it fails.
This is to make sure that if two programs can create the same file
but shouldn't work on it the same time, the file isn't opened
multiple times.
aa=os.open("c:\\temp\\a.txt",os.O_RDWR|os.O_EXCL|o s.O_CREAT)
os.close(aa)
aa=os.open("c:\\temp\\a.txt",os.O_RDWR|os.O_CREAT)


I suppose this should again be the instrcution two lines above;
this actually works. (At least on my linux box, if it didn't on
your XP box, that is a bug)
Traceback (most recent call last):
File "<string>", line 1, in <string>
OSError: [Errno 17] File exists: 'c:\\temp\\a.txt'


Which is exactly as it should, provided you actually used the os.O_EXCL
flag twice.

--
Antoon Pardon
Jul 18 '05 #2
Antoon Pardon wrote:
Why? What is it about the exclusive flag that
makes you like to use it?


Ok. Thanks, I misunderstood the meaning of flag.
What I' like to do is to open file and keep it exclusive locked for me.
Apparently this flag is not for me.

Eino Mäkitalo
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Tim Gahnstrom | last post by:
rdiff-backup is aperently written in Python and when I run it in a special way I get some funy Python errors. Does anyone know if linux python have some issues with working with fat32 or usb...
20
by: Ilias Lazaridis | last post by:
" A cooperation between Sun Microsystems and IBM&Co. in conjunction with liberal & high evolutive communities would result in an nearly unbeatable programming platform. My evaluation has shown:...
1
by: Fouff | last post by:
Hello all. I have a small question concerning the functions open(...) and file(...) with python 2.4 In the online version of the documentation in the build-in functions (section 2.1...
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
158
by: Giovanni Bajo | last post by:
Hello, I just read this mail by Brett Cannon: http://mail.python.org/pipermail/python-dev/2006-October/069139.html where the "PSF infrastracture committee", after weeks of evaluation, recommends...
4
by: Martitza | last post by:
Hi. I work for a small company (actually in process of forming) interested in embedding or extending python as part of our commercial non-open-source product. We have legal counsel, but are...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.