Discussion:
[Tutor] Portalocker
Mike Wagman
2003-07-17 19:41:01 UTC
Permalink
Does not seem to be working.

Can anyone send me a piece of code that will open a file, and when that
file is open - I can't open it from another python program.
S***@aol.com
2003-07-17 20:03:04 UTC
Permalink
import portalocker
file=open("C:\My Documents\log.txt", "r+")
portalocker.lock(file, portalocker.LOCK_EX)
Traceback (most recent call last):
File "<pyshell#13>", line 1, in ?
portalocker.lock(file, portalocker.LOCK_EX)
AttributeError: 'module' object has no attribute 'lock'

I rechecked to see if I installed the module correctly and I did. Anyone
know why this is happening? Thanks in advance.
lonetwin
2003-07-18 07:30:02 UTC
Permalink
Hi there,
Could you possibly post a URL for portalocker ??
At first glance I can hazard a guess, since I too have done such mistakes when
playing in the interpreter.
Post by S***@aol.com
import portalocker
file=open("C:\My Documents\log.txt", "r+")
portalocker.lock(file, portalocker.LOCK_EX)
File "<pyshell#13>", line 1, in ?
portalocker.lock(file, portalocker.LOCK_EX)
AttributeError: 'module' object has no attribute 'lock'
The error message is pretty clear. You seem to be calling a non-existant
method in the module 'portalocker' called 'lock' ('module' object has no
attribute 'lock')

Normally, for me, something like this happens in the interpreter when I
stupidly try to use a method that belongs to a class with the same name is
the module. What I mean is, look at the portalocker module and see if there
is a class called 'portalocker' which you have to instantiate before calling
the 'lock' method on the instance.

Peace
Steve
--
It is easier to resist at the beginning than at the end.
-- Leonardo da Vinci
S***@aol.com
2003-07-20 21:06:02 UTC
Permalink
The URL for the portalocker module is:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203

Loading...