Re: singleton problems

2010-10-03 Thread Bruno Desthuilliers
jimgardener a écrit : > hi Steven, > can you explain that?I didn't quite get it. > I have a module say 'managerutils' where I have a class > MyManager.. What Steven was talking about was to NOT use a class at all. Modules are objects and have their own namespace. And you can use threading.locals i

Re: singleton problems

2010-10-03 Thread harryos
thanks Arnold..that made it quite clear harry On Oct 3, 4:11 pm, Arnaud Delobelle wrote: > Arnaud Delobelle writes: > -- http://mail.python.org/mailman/listinfo/python-list

Re: singleton problems

2010-10-03 Thread Arnaud Delobelle
Arnaud Delobelle writes: [...] > That's because overriding __new__ doesn't prevent __init__ from being > executed. The reason for this is that when you do: > > MySingle('jeff') > > what is executed is: > > MySingle.__metaclass__.__call__('jeff') Oops. I meant: MySingle.__metaclass_

Re: singleton problems

2010-10-03 Thread Arnaud Delobelle
harryos writes: > hi > I have been trying out singleton design pattern implementations..I > wrote this, > > > class Singleton(object): > _instance = None > def __new__(self, *args, **kwargs): > if not self._instance: > self._instance = super(Singleton, self).__new__(se

Re: singleton problems

2010-10-03 Thread jimgardener
hi Steven, can you explain that?I didn't quite get it. I have a module say 'managerutils' where I have a class MyManager.. ie, managerutils.py -- class MyManager(object): def __init__(self): self.myaddresses={} ... from another main program ,if I call , import managerutils

Re: singleton problems

2010-10-03 Thread harryos
thanks Steven..that was very helpful..thanks a lot harry > Since __new__ is called before the instance exists, it doesn't receive an > instance as the first argument. Instead it receives the class. While you > can call the parameter anything you like, it is conventional to call it > cls rather than

Re: singleton problems

2010-10-03 Thread Steven D'Aprano
On Sun, 03 Oct 2010 01:55:00 -0700, harryos wrote: > hi > I have been trying out singleton design pattern implementations..I wrote > this, > > > class Singleton(object): > _instance = None > def __new__(self, *args, **kwargs): > if not self._instance: > self._instance

singleton problems

2010-10-03 Thread harryos
hi I have been trying out singleton design pattern implementations..I wrote this, class Singleton(object): _instance = None def __new__(self, *args, **kwargs): if not self._instance: self._instance = super(Singleton, self).__new__(self, *args, **kwargs) return