pretty basic instantiation question

meithamj at gmail.com meithamj at gmail.com
Mon Oct 23 20:36:14 EDT 2006


Why do you need to know the number of instances. I know that Python
does not support Class Variable, but you can always create a global
variable and increase it whenever you add a new instance. this will
keep a record for you of how many instances you have.

sittner at lkb.ens.fr wrote:
> i'm very new to python, but i have a pretty basic question:
> let's say i have a class, and i need to create a different number of
> instances (changes every time - and i can't know the number in advance) in
> a loop.
> a function receives the number of instances that are needed, and creates
> them like,
> a=Myclass()
> b=Myclass()
> .
> .
> .
> .
> .
> .
> 
> what's the easiest way to go about this?
> 
> thanks,
> A




More information about the Python-list mailing list