globally available objects
From: Steve (lonetwin_at_gmail.com)
Date: 10/29/04
- Next message: Werner Merkl: "Re: py2exe and CD-ROM ISO Level 1"
- Previous message: Jeremy Jones: "Re: Multiple XML-RPC calls over the same connection?"
- Next in thread: Diez B. Roggisch: "Re: globally available objects"
- Reply: Diez B. Roggisch: "Re: globally available objects"
- Maybe reply: Terry Reedy: "Re: globally available objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 29 Oct 2004 16:04:13 +0530 To: Python List <python-list@python.org>
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 global_objs.py) 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 global_objs.py ?? I feel it would. Assuming this is correct,
how do I ensure that once created, the objects in global_objs.py 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 ...am I making sense to anyone else here ??
Regards
Steve
- Next message: Werner Merkl: "Re: py2exe and CD-ROM ISO Level 1"
- Previous message: Jeremy Jones: "Re: Multiple XML-RPC calls over the same connection?"
- Next in thread: Diez B. Roggisch: "Re: globally available objects"
- Reply: Diez B. Roggisch: "Re: globally available objects"
- Maybe reply: Terry Reedy: "Re: globally available objects"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|