globally available objects

Steve lonetwin at
Fri Oct 29 12:34:13 CEST 2004

Hi list,
      I speak with ignorance but I'd like to know if something like
this is even possible:
I would like to create an object while importing a module only the
first time it get's imported. I wonder imports already work in this
manner. For example, in a module (say I would have:

import mylogger
import error_hdlr

my_log_obj = mylogger.init_log()  # This may involve some file I/O
my_err_obj = myerror_hdlr.init() # Thiis also might involve some file I/O

now, at run time, would mylogger.init_log() be called each for each
import of ?? I feel it would. Assuming this is correct,
how do I ensure that once created, the objects in do
not get recreated. ....maybe I need to redefine __import__ or
__getattr__ ?? If yes, how do I know from within such functions
whether the objects have been created ??

ehe I making sense to anyone else here ??


More information about the Python-list mailing list