Re: How to control the creation of an instance?

2007-06-03 Thread KingMax
On Jun 3, 2:17 pm, 7stud <[EMAIL PROTECTED]> wrote: > On Jun 2, 10:31 pm, lialie <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > suppose i have a free_object list[Sample1, Smaple2]. when create a > > new object sample(*args, **kwds), if free_object_list isn't empty, just > > pop one from free_ob

Re: How to control the creation of an instance?

2007-06-03 Thread 7stud
On Jun 3, 12:50 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sat, 02 Jun 2007 23:25:49 -0700, 7stud wrote: > > Oops. This line: > > >> temp = object.__new__(Sample, args, kwds) > > > should be: > > > temp = object.__new__(cls, args, kwds) > > > although it would seem that cls is always goin

Re: How to control the creation of an instance?

2007-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2007 23:25:49 -0700, 7stud wrote: > Oops. This line: > >> temp = object.__new__(Sample, args, kwds) > > should be: > > temp = object.__new__(cls, args, kwds) > > although it would seem that cls is always going to be Sample, so I'm > not sure what practical difference that makes

Re: How to control the creation of an instance?

2007-06-02 Thread 7stud
On Jun 3, 12:17 am, 7stud <[EMAIL PROTECTED]> wrote: > On Jun 2, 10:31 pm, lialie <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > suppose i have a free_object list[Sample1, Smaple2]. when create a > > new object sample(*args, **kwds), if free_object_list isn't empty, just > > pop one from free_o

Re: How to control the creation of an instance?

2007-06-02 Thread 7stud
On Jun 2, 10:31 pm, lialie <[EMAIL PROTECTED]> wrote: > Hi, > > suppose i have a free_object list[Sample1, Smaple2]. when create a > new object sample(*args, **kwds), if free_object_list isn't empty, just > pop one from free_object_list instead of creating a new instance. > > any way to do this

Re: How to control the creation of an instance?

2007-06-02 Thread 7stud
I just noticed that in your code you used pop(0). It's not efficient to pop an element off the front of a list because after doing so, every other element in the list has to be moved over to the left one position. If you pop() an element off the end of the list, then the first element in the list

Re: How to control the creation of an instance?

2007-06-02 Thread 7stud
On Jun 2, 10:31 pm, lialie <[EMAIL PROTECTED]> wrote: > Hi, > > suppose i have a free_object list[Sample1, Smaple2]. when create a > new object sample(*args, **kwds), if free_object_list isn't empty, just > pop one from free_object_list instead of creating a new instance. > > any way to do this

How to control the creation of an instance?

2007-06-02 Thread lialie
Hi, suppose i have a free_object list[Sample1, Smaple2]. when create a new object sample(*args, **kwds), if free_object_list isn't empty, just pop one from free_object_list instead of creating a new instance. any way to do this? I do some work as follows: class Sample(object): used_object =