globally available objects

Steve lonetwin at gmail.com
Fri Oct 29 13:39:22 CEST 2004


Hi Diez,

On Fri, 29 Oct 2004 12:58:19 +0200, Diez B. Roggisch <deetsnospam at web.de> wrote:
> Steve wrote:
> 
> >
> > ehe ...am I making sense to anyone else here ??
> 
> You do, but if you put the same amount of time writing this message in
> writing a simple test module for yourself and importing it, you've had seen
> that it in fact works the way you want it: a module is only imported once.
Yes I did know that, however, I was not sure if objects that are
created during imports would be the same. Anyways, I did create a test
scriptlets and verified that it indeed is that way !!!!
------------------------------------------------------------------------------------
[steve at sfernandez20 ~]$ cat foo.py 
print "calling file().read()"
s = file('test').read()

[steve at sfernandez20 ~]$ cat first.py 
#!/usr/bin/python
from foo import s
print id(s)

[steve at sfernandez20 ~]$ cat second.py
#!/usr/bin/python
from foo import s
print id(s)

[steve at sfernandez20 ~]$ python

Python 2.3.3 (#2, Feb 17 2004, 11:45:40) 
[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import first, second
calling file().read()
1077624320
1077624320
>>>
------------------------------------------------------------------------------------

> No offense intended, btw - I just wanted to point out that in python its
> common to simply fire up the interpreter and poke around to test things.

No offense taken, thanks for the suggestion. I did try some tests but
with the wrong intent. I guess I just got bogged down with the actual
way to emulate the behaviour (tried overloading __import__ and stuff
like that). Guess I need more coffee !!

In any case, I still would like to have a look at Pierre singleton
implementation,

Regards
Steve



More information about the Python-list mailing list