class initialization problem

alex23 wuwei23 at gmail.com
Fri Sep 18 06:14:45 CEST 2009


On Sep 18, 1:27 pm, rantingrick <rantingr... at gmail.com> wrote:
> ok i have a class and in it's constructor i want to create a copy of
> it as an attribute, i have tried super, __new__, and noting seems to
> work, please help!
>
> class A(base):
>     def __init__(self):
>         super(A, self).__init__()
>         self.nested = ?
>
> think of a nested list [ [] ] but with object "A" as the toplevel list
> and having an instance of A in the attribute "nested"

Sorry, do you want an a copy of the instance or of the class?

If you mean the class, self.nested = self.__class__
If you mean the instance, self.nested = self



More information about the Python-list mailing list