Howto dynamically add object to the list
Emile van Sebille
emile at fenx.com
Thu Jul 26 07:37:48 EDT 2001
To create an instance of the class Patient, invoke the class with the
constructor arguments, for example:
pacjenci.append(Patient()) #note the extra ()'s
HTH,
--
Emile van Sebille
emile at fenx.com
---------
"Piotr Legiecki" <piotrlg at sci.pam.szczecin.pl> wrote in message
news:3B5FF76C.20B6AD98 at sci.pam.szczecin.pl...
> Hi
>
> I have such a class
>
> class Patient:
> x=0
> ...
>
> And such a code to add objects of class Patient to a growing list:
>
> ...
> while curPatient!=-1:
> pacjenci.append(Patient)
> curPatient=GetNextPatient(allPat, curPatient, pacjenci[i])
> .....
>
> Well, it is wrong code (I add classes Patient ?! not objects of this
> class). So how to add an object to the list in such a situation?
>
> something like:
> ....
> while curPatient!=-1:
> obj=Patient
> pacjenci.append(obj)
> curPatient=GetNextPatient(allPat, curPatient, pacjenci[i])
> .....
>
> Is it ok?
>
> --
> Regards
> Piotr Legiecki
More information about the Python-list
mailing list