Re: How to initialize a class variable once

2008-12-09 Thread Brian Allen Vanderburg II
[EMAIL PROTECTED] wrote: Unless you are calling reload() on the module, it will only ever get _loaded_ once. Each additional import will just yield the existing module. Perhaps if you post an example of the behavior that leads you to believe that the class variables are getting reinitialized I

Re: How to initialize a class variable once

2008-12-09 Thread Joe Strout
On Dec 9, 2008, at 4:31 AM, Brian Allen Vanderburg II wrote: There is one situation where a module can be imported/executed twice, if it is the __main__ module. That's an excellent point -- this is something I've run into, and it always feels a bit awkward to code around it. What's the

Re: How to initialize a class variable once

2008-12-09 Thread George Sakkis
On Dec 9, 10:36 am, Joe Strout [EMAIL PROTECTED] wrote: On Dec 9, 2008, at 4:31 AM, Brian Allen Vanderburg II wrote: There is one situation where a module can be imported/executed   twice, if it is the __main__ module. That's an excellent point -- this is something I've run into, and it  

Re: How to initialize a class variable once

2008-12-09 Thread Roy Smith
In article [EMAIL PROTECTED], Joe Strout [EMAIL PROTECTED] wrote: On Dec 9, 2008, at 4:31 AM, Brian Allen Vanderburg II wrote: There is one situation where a module can be imported/executed twice, if it is the __main__ module. Anyway, thanks for pointing this out; I bet it's the root

How to initialize a class variable once

2008-12-08 Thread Roy Smith
I've got a class with a class variable: class Foo: _map = {} How do I make sure this only gets initialized the *first* time the module containing the class is imported? What appears to be happening as it stands is each time the module gets imported, Foo._map get re- initialized. --

Re: How to initialize a class variable once

2008-12-08 Thread Matimus
On Dec 8, 8:08 pm, Roy Smith [EMAIL PROTECTED] wrote: I've got a class with a class variable: class Foo:    _map = {} How do I make sure this only gets initialized the *first* time the module containing the class is imported?  What appears to be happening as it stands is each time the

Re: How to initialize a class variable once

2008-12-08 Thread alex23
On Dec 9, 2:08 pm, Roy Smith [EMAIL PROTECTED] wrote: I've got a class with a class variable: class Foo:    _map = {} How do I make sure this only gets initialized the *first* time the module containing the class is imported?  What appears to be happening as it stands is each time the

Re: How to initialize a class variable once

2008-12-08 Thread John Machin
On Dec 9, 3:36 pm, Matimus [EMAIL PROTECTED] wrote: On Dec 8, 8:08 pm, Roy Smith [EMAIL PROTECTED] wrote: I've got a class with a class variable: class Foo:    _map = {} How do I make sure this only gets initialized the *first* time the module containing the class is imported?  What

Re: How to initialize a class variable once

2008-12-08 Thread Benjamin Kaplan
On Mon, Dec 8, 2008 at 11:44 PM, John Machin [EMAIL PROTECTED] wrote: On Dec 9, 3:36 pm, Matimus [EMAIL PROTECTED] wrote: On Dec 8, 8:08 pm, Roy Smith [EMAIL PROTECTED] wrote: I've got a class with a class variable: class Foo: _map = {} How do I make sure this only gets

Re: How to initialize a class variable once

2008-12-08 Thread Roy Smith
In article [EMAIL PROTECTED], alex23 [EMAIL PROTECTED] wrote: You might need to provide some more details about your code. It's going to take me some time to generate a minimal test case. -- http://mail.python.org/mailman/listinfo/python-list