how to declare array of class instances
kiran.k
kirank at giasbma.vsnl.net.in
Mon Oct 11 08:40:02 EDT 1999
hi everyone :-)
1>
Could anyone tell me howto declare an array (or list) of class
instances.
say--
class trial():
tmp=0
def func(self,x):
self.tmp=x
:
inst=trial() #instance of trial class
arr=[]
arr.append(inst)
however, all instances of trial as arr[0-n] seem to have the same
values of local variables in the class.
i.e arr[0].tmp==arr[n].tmp
even if the input from keyboard is taken as
for loop:
arr[n].func( input(""))
arr[0].tmp would hold the last value inputted in the for loop
i.e that of arr[n].tmp
2> suppose a function takes three parameters
def func(self,x,y,z):
--
if i want the parameters to be keyboard inputs,
is there any other way besides
func( input(""), input(""), input(""))
thanking you in anticipation
kiran.k
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Software is like sex,
its better when its free
--Linus Torvalds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Python-list
mailing list