Re: Loading a file only once into an object and being able to access it from other modules - still have a problem

2004-12-09 Thread Jeff Shannon
Philippe C. Martin wrote: Hi, After all of you answers, I though I had it straight, yet . This is what I am doing: class SC_ISO_7816: __m_loaded = None .. def __init__(self): if SC_ISO_7816.__m_loaded == None: SC_ISO_7816.__m_loaded = True print 'LOADING'

Re: Loading a file only once into an object and being able to access it from other modules - still have a problem

2004-12-09 Thread Philippe C. Martin
>Well, from the looks of things, you don't seem to understand the >basic idea of instances and instance attributes.  There is a key >difference between SC_ISO_67816.__m_loaded and self.SW1_DICT, >and that is that the former one is seen by *all instances*, while >the latter is an attribute in *only

Re: Loading a file only once into an object and being able to access it from other modules - still have a problem

2004-12-09 Thread Peter Hansen
Philippe C. Martin wrote: class SC_ISO_7816: __m_loaded = None Please don't use tabs in code you post here. Many newsreaders have trouble displaying them, and make the code look like it does above (i.e. no indentation at all) which makes it hard to understand. .. def __init__(self):

Re: Loading a file only once into an object and being able to access it from other modules - still have a problem

2004-12-09 Thread Philippe C. Martin
Hi, After all of you answers, I though I had it straight, yet . This is what I am doing: class SC_ISO_7816: __m_loaded = None .. def __init__(self): """ """ if SC_ISO_7816.__m_loaded == None: SC_ISO_7816.__m_loaded = True print 'LOAD

Re: Loading a file only once into an object and being able to access it from other modules

2004-12-07 Thread Peter Hansen
Philippe C. Martin wrote: Thank you all for your answers, I guess I would not have made Python 101:-) As far as I was concerned, importing a module twice would have resulted in loading the file twice. Background on that: importing the module the first time causes the code in it to be executed (i.

Re: Loading a file only once into an object and being able to access it from other modules

2004-12-07 Thread Philippe C. Martin
Thank you all for your answers, I guess I would not have made Python 101:-) As far as I was concerned, importing a module twice would have resulted in loading the file twice. Regards, Philippe -- * Philippe C. Martin SnakeCard LLC www.snakecard.com *

Re: Loading a file only once into an object and being able to access it from other modules

2004-12-07 Thread Andrew James
You're looking for the Singleton pattern to ensure that only one instance of your class is instantiated at a time. There's a particularly useful discussion about this at: http://c2.com/cgi/wiki?PythonSingleton I suggest you try the different methods out and pick the one best suited to your situ

Re: Loading a file only once into an object and being able to access it from other modules

2004-12-07 Thread Thomas Guettler
Am Tue, 07 Dec 2004 09:25:57 -0600 schrieb Philippe C. Martin: > This is a basic question I'm sure but I do not know wether to use > __builtin__, > global, or a static method: > > I have a very large XML file that I load into dictionnaries defined in a > class > located in a module that is i

Re: Loading a file only once into an object and being able to access it from other modules

2004-12-07 Thread Remy Blank
Philippe C. Martin wrote: > I have a very large XML file that I load into dictionnaries defined in a > class > located in a module that is imported in many places. > > Since the loading process is very slow, I would like the file not to be > loaded > on import or class instantiation, but only

Loading a file only once into an object and being able to access it from other modules

2004-12-07 Thread Philippe C. Martin
This is a basic question I'm sure but I do not know wether to use __builtin__, global, or a static method: I have a very large XML file that I load into dictionnaries defined in a class located in a module that is imported in many places. Since the loading process is very slow, I would like th