Re: Creating classes and objects more than once?

2008-11-28 Thread Viktor Kerkez
On Nov 28, 9:35 am, Carl Banks <[EMAIL PROTECTED]> wrote: > However, I'm not so sure the effect of os.chdir() on the import path > is a good idea. I'm not actually using os.chidir(), I just used it here to create a clearer example. Here is the simplest representation of the problem: http://www.n

Re: Creating classes and objects more than once?

2008-11-27 Thread Viktor Kerkez
On Nov 28, 12:32 am, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > The Python position on singletons is generally to just use a module > instead (preferred), or apply the Borg > pattern:http://code.activestate.com/recipes/66531/ The same problem appears if I use the module (as I pointed in the firs

Re: Creating classes and objects more than once?

2008-11-27 Thread Viktor Kerkez
A better way to do this was http://pastebin.com/m1130d1fe :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating classes and objects more than once?

2008-11-27 Thread Viktor Kerkez
But this means that there is no way to create a safe Singleton in python, because the classes are also created twice. This is the problem that I encountered. I created a complex implementation of a Singleton pattern using metaclasses because I needed the __init__ method to be called just once and

Creating classes and objects more than once?

2008-11-27 Thread Viktor Kerkez
Here is the situation: $ ls test $ cd test $ ls __init__.py data.py $ cat __init__.py $ cat data.py DATA = {} $ cd .. $ python >>> import os >>> from test.data import DATA >>> DATA['something'] = 33 >>> os.chdir('test') >>> from data import DATA as NEW_DATA >>> DATA {'something': 33} >>> NEW_DAT