Re: getattr nested attributes

2008-08-15 Thread Fredrik Lundh
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

Re: getattr nested attributes

2008-08-15 Thread Paul Boddie
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")

Re: getattr nested attributes

2008-08-15 Thread Steven D'Aprano
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): >

Re: getattr nested attributes

2008-08-15 Thread Wojtek Walczak
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) >

Re: getattr nested attributes

2008-08-15 Thread Peter Otten
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):

Re: getattr nested attributes

2008-08-15 Thread Gregor Horvath
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

Re: getattr nested attributes

2008-08-15 Thread Peter Otten
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

Re: getattr nested attributes

2008-08-15 Thread Christian Heimes
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

getattr nested attributes

2008-08-15 Thread Gregor Horvath
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