Subattributes of classes

geek+ at cmu.edu geek+ at cmu.edu
Mon Apr 5 11:42:04 EDT 1999


Then <aa8vb at vislab.epa.gov> spoke up and said:
> 
>    class A:
>      def __init__( self ):
>        self.attr = 123
>        self.attr.subattr = 456        # <--------- Error!
> 
>    a = A()
> 
> 
> This generates an error as I would have expected.
> 
> However, I see the same syntax in:
>    demos/tkinter/matt/canvas-with-scrollbars.py

because in the demo you pointed to, they are setting sub-attributes of
an integer.  The object 123 is immutable.  Do it this way:

class foo: pass
f = foo()
f.bar = foo()
f.bar.baz = 123

-- 
=====================================================================
| JAVA must have been developed in the wilds of West Virginia.      |
| After all, why else would it support only single inheritance??    |
=====================================================================
| Finger geek at cmu.edu for my public key.                            |
=====================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 266 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/19990405/ba7fa072/attachment.sig>


More information about the Python-list mailing list