Subattributes of classes

Oleg Broytmann phd at sun.med.ru
Mon Apr 5 11:43:26 EDT 1999


On Mon, 5 Apr 1999, Randall Hopper wrote:
>    class A:
>      def __init__( self ):
>        self.attr = 123
>        self.attr.subattr = 456        # <--------- Error!
> 
>    a = A()
> 
> 
> This generates an error as I would have expected.
[skipped]
> Why?

   Try this:

   class B:
      pass

   class A:
     def __init__( self ):
       self.attr = B()
       self.attr.subattr = 456

   a = A()

> Randall
> 
> 
> 

Oleg.
---- 
    Oleg Broytmann  National Research Surgery Centre  http://sun.med.ru/~phd/
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list