[Pythonmac-SIG] silly variable evaluation question
savageb
savageb@pacbell.net
Sat, 27 Nov 1999 00:18:26 -0800
> I'm beating my head into the monitor trying to do the following:
>
> import Res
> foo = dir(Res)[0]
> print Res.foo.__doc__
>
> this throws an obvious error as foo isn't defined in Res. So how do I
> evaluate foo in context. In tcl I'd just throw some brackets around
> that puppy and problem solved but I appear to be missing something
> crucial here.
>
> Dante
I think you are trying to do something like the following:
import Res
for i in dir(Res):
try:
print i; print '\t',
exec( "print Res.%s.__doc__" % i )
except AttributeError:
# prevent things like strings from raising exceptions
print "no docstring"