No, that won't work, but these alternatives do:
<code>
>>> class A:
... pass
...
>>> class B:
... pass
...
>>> a = A()
>>> a.b = B()
>>> a.b.prop = 1234
>>> print getattr(getattr(a, 'b'), 'prop')
1234
>>> print getattr(a.b, 'prop')
1234
</code>
/S
-----Original Message-----
From: Lloyd Kvam <[EMAIL PROTECTED]>
Date: Mon, 23 Jul 2001 16:50:49 -0400
To: Active Python <[EMAIL PROTECTED]>
Subject: Using getattr() with "dotted" names
> 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]
> <A HREF="http://listserv.ActiveState.com/mailman/listinfo/activepython"
>TARGET="_new"><FONT
>COLOR="BLUE">http://listserv.ActiveState.com/mailman/listinfo/activepython</FONT></A>
>
--
_______________________________________________
FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
Talk More, Pay Less with Net2Phone Direct(R), up to 1500 minutes free!
http://www.net2phone.com/cgi-bin/link.cgi?143
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython