Re: How to create a limited set of instanceses of a class

2006-07-02 Thread Alex Martelli
madpython <[EMAIL PROTECTED]> wrote: > Thanks, Alex, again. The lesson has been taught. I appreciate very much > you spent time trying to help. Indeed the culprit of that infrequent > infinite loops was that bound reference "item" in the printing > loop. But frankly i thought that it only existed

Re: How to create a limited set of instanceses of a class

2006-07-02 Thread madpython
Thanks, Alex, again. The lesson has been taught. I appreciate very much you spent time trying to help. Indeed the culprit of that infrequent infinite loops was that bound reference "item" in the printing loop. But frankly i thought that it only existed inside that loop. Apparently I was wrong and g

Re: How to create a limited set of instanceses of a class

2006-07-02 Thread Alex Martelli
madpython <[EMAIL PROTECTED]> wrote: > Thanks Alex and Scott for your lead. It would've taken me forever > trying to figure it out by myself :) > > I am affraid I didn't specify initially one thing and that led to a > confusion: there is no need to pick an instance from the weakref > dictionary,

Re: How to create a limited set of instanceses of a class

2006-07-02 Thread madpython
Thanks Alex and Scott for your lead. It would've taken me forever trying to figure it out by myself :) I am affraid I didn't specify initially one thing and that led to a confusion: there is no need to pick an instance from the weakref dictionary, just return None if there are already 5 instances.

Re: How to create a limited set of instanceses of a class

2006-07-01 Thread Scott David Daniels
madpython wrote: > For the pure theory sake and mind expansion i got a question. > Experimenting with __new__ i found out how to create a singleton. > class SingleStr(object): > def __new__(cls,*args,**kwargs): > instance=cls.__dict__.get('instance') > if instance: >

Re: How to create a limited set of instanceses of a class

2006-07-01 Thread Alex Martelli
madpython <[EMAIL PROTECTED]> wrote: > For the pure theory sake and mind expansion i got a question. > Experimenting with __new__ i found out how to create a singleton. > class SingleStr(object): > def __new__(cls,*args,**kwargs): > instance=cls.__dict__.get('instance') > if in

How to create a limited set of instanceses of a class

2006-07-01 Thread madpython
For the pure theory sake and mind expansion i got a question. Experimenting with __new__ i found out how to create a singleton. class SingleStr(object): def __new__(cls,*args,**kwargs): instance=cls.__dict__.get('instance') if instance: return instance cls.in