How to I lock a file ?

F

fowlertrainer

Hello python-list,

On windows I try with this:

import os
f1=file('a',"w+",os.O_EXCL|os.O_WRONLY)
f1.write("0")
f2=file('a',"w+",os.O_EXCL|os.O_WRONLY)
f2.write("1")
f1.close()
f2.close()

But it is not working...

So how to I lock this file to prevent from next opening ?

Thanx.
 
D

Dennis Lee Bieber

(e-mail address removed) fed this fish to the penguins on Friday 28
November 2003 03:30 am:
On windows I try with this:

import os
f1=file('a',"w+",os.O_EXCL|os.O_WRONLY)
But it is not working...

So how to I lock this file to prevent from next opening ?

First step: read the documentation for file() (section 2.1 of the
Library reference)

file(filename[, mode[, bufsize]])

Does anything in that definition imply being able to set locking?

Hint, anything that is a builtin to Python is unlikely to be using
constants defined in an imported module.

Second step: read the documentation for the os module (6.1.3 in my
copy).

open(file, flags[, mode])


In short, you are trying to mix flags from two separate types of file
operations.

--
 
M

Miki Tebeka

Hello,
f1=file('a',"w+",os.O_EXCL|os.O_WRONLY)
Have a look at the documentation, the 3'rd parameter to "file" is the buffer size.
So how to I lock this file to prevent from next opening ?
Use os.open or the win32all package (with CreateFile).

HTH.
Miki
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top