473,698 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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",o s.O_RDWR|os.O_C REAT)
os.close(aa)
aa=os.open("c:\ \temp\\a.txt",o s.O_RDWR|os.O_C REAT)
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",o s.O_RDWR|os.O_E XCL|os.O_CREAT)
os.close(aa)
aa=os.open("c:\ \temp\\a.txt",o s.O_RDWR|os.O_C REAT)

Traceback (most recent call last):
File "<string>", line 1, in <string>
OSError: [Errno 17] File exists: 'c:\\temp\\a.tx t'
Jul 18 '05 #1
2 4931
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",o s.O_RDWR|os.O_C REAT)
os.close(aa)
aa=os.open("c:\ \temp\\a.txt",o s.O_RDWR|os.O_C REAT)
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",o s.O_RDWR|os.O_E XCL|os.O_CREAT)
os.close(aa)
aa=os.open("c:\ \temp\\a.txt",o s.O_RDWR|os.O_C REAT)


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.tx t'


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
35549
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 and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate),
3
2953
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 drives? To tracebacks are provided below for more information. This is the version information I get when I start Python ojn my Fedora Core 2 computer. -bash-2.05b$ python Python 2.3.3 (#1, May 7 2004, 10:31:40)
20
2333
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: this is a non achievable goal, as stubborness and egoism rules - instead of reason and cooperation. Thus I leave all those ridiculous folks behind, which will continue to do an excellent job in keeping the very promising JAVA platform far
1
1457
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 http://docs.python.org/lib/built-in-funcs.html) here is an quote of the file(...) doc : > The file() constructor is new in Python 2.2 and is an alias for open(). > Both spellings are equivalent.
50
5711
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
6380
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 using a non open source tracker (called JIRA - never heard before of course) for Python itself. Does this smell "Bitkeeper fiasco" to anyone else than me? --
4
2120
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 interested in the spirit as well as the letter of the law. Not much seems to have been written about the python license since version 2, so pointers to more recent discussions or contacts are appreciated. If this is not the right place to ask these...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.