Gregor Horvath wrote:
Thank's, but this does not work for this case:
class A(object):
test = "test"
class B(object):
a = [A(),]
In [70]: reduce(getattr, "a[0].test".split("."), B)
---
Traceback (most recen
On 15 Aug, 10:35, Gregor Horvath <[EMAIL PROTECTED]> wrote:
>
> : type object 'B' has no attribute
> 'a.test'
You have to realise that attributes can have names beyond those
supported by the usual attribute access syntax. For example:
class C: pass
setattr(C, "x.y", 123)
getattr(C, "x.y")
On Fri, 15 Aug 2008 11:12:04 +0200, Gregor Horvath wrote:
> Peter Otten schrieb:
>
>> make your own function that loops over the attributes, or spell it
>>
> reduce(getattr, "a.test".split("."), B)
>> 'test'
>>
>>
> Thank's, but this does not work for this case:
>
> class A(object):
>
On Fri, 15 Aug 2008 11:12:04 +0200, Gregor Horvath wrote:
> Thank's, but this does not work for this case:
>
> class A(object):
> test = "test"
>
> class B(object):
> a = [A(),]
>
> In [70]: reduce(getattr, "a[0].test".split("."), B)
>
Gregor Horvath wrote:
> Peter Otten schrieb:
>
>> make your own function that loops over the attributes, or spell it
>>
> reduce(getattr, "a.test".split("."), B)
>> 'test'
>>
>
> Thank's, but this does not work for this case:
>
> class A(object):
> test = "test"
>
> class B(object):
Peter Otten schrieb:
make your own function that loops over the attributes, or spell it
reduce(getattr, "a.test".split("."), B)
'test'
Thank's, but this does not work for this case:
class A(object):
test = "test"
class B(object):
a = [A(),]
In [70]: reduce(getattr, "a[0].test".s
Gregor Horvath wrote:
> 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")
> ---
> Traceback (most recent
Gregor Horvath wrote:
any help?
I guess you missunderstood the sentence "For example, getattr(x,
'foobar') is equivalent to x.foobar.". getattr(x, "foo.bar") is not
equivalant to x.foo.bar.
--
http://mail.python.org/mailman/listinfo/python-list
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")
---
Traceback (most recent call last)
/ in ()
: type object 'B' has no attribut