How to have application-wide global objects
Fredrik Lundh
fredrik at pythonware.com
Thu Jul 13 13:46:49 EDT 2006
Jeremy Sanders wrote:
>> "import" doesn't create new objects, so that's not very likely. can you
>> post some code so we don't have to guess what you've tried and not ?
>
> It does if you mess around with sys.path between doing two imports of the
> same thing (at least I found out the hard way on Python 2.4). I'm not sure
> this is considered a bug or a "don't do that then" problem.
it's not a problem at all, because "doing two imports of the same thing"
will fetch the second thing from the module cache, no matter what you do
to the path.
$ more module.py
# simulate creating a new object
print "CREATE NEW OBJECT"
$ python
>>> import sys
>>> import module
CREATE NEW OBJECT
>>> sys.path.insert(0, "foobar")
>>> import module
>>> sys.path = None
>>> import module
if you got some other result, you didn't just import the same thing twice...
</F>
More information about the Python-list
mailing list