Thanks for your suggestions. Our code for this issue finally became:
def get(self, field):
flist = field.split('.')
return reduce( getattr, flist, self)
Lloyd Kvam wrote:
>
> I have a project where classes may be nested. The Python interpreter will handle
>nested instance references without any difficulty (e.g. print a.b.prop).
>
> Is there a good way to handle attribute references in getattr to get the same effect?
> (e.g. print getattr( a, 'b.prop') )
>
> class A:
> pass
> class B:
> pass
> >>>>>>>>>
> a = A()
> a.b = B()
> a.b.prop = 1234
> print a.b.prop
> <<<<<<<<< All work OK
>
> print getattr( a, 'b.prop') does not work.
>
> --
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
>
> voice: 603-443-6155
> fax: 801-459-9582
> _______________________________________________
> ActivePython mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activepython
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-443-6155
fax: 801-459-9582
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython