getattr nested attributes

Gregor Horvath gh at gregor-horvath.com
Fri Aug 15 04:35:31 EDT 2008


Hi,

class A(object):
     test = "test"

class B(object):
     a = A()


In [36]: B.a.test
Out[36]: 'test'

In [37]: getattr(B, "a.test")
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'>        Traceback (most recent call last)

/<ipython console> in <module>()

<type 'exceptions.AttributeError'>: type object 'B' has no attribute 
'a.test'

???

Documentation says B.a.test and getattr(B, "a.test") should be equivalent.

http://docs.python.org/lib/built-in-funcs.html

any help?

Greg



More information about the Python-list mailing list