evaluate a variable
Ignacio Vazquez-Abrams
ignacio at openservices.net
Fri Sep 14 09:57:18 EDT 2001
On Fri, 14 Sep 2001 dimitry_snezhkov at yahoo.com wrote:
> I just started learning Python. Of, course , reading output of
> __doc__
> is very pleasant. I decided to output documentation for every def in
> a module. How do I evaluate a variable that is dynamicaly generated.
> Sort of hello.$bye.see_ya in Perl :
>
> Here's my code :
>
> import sys
>
> for each in range(len(dir(sys))):
> method='sys' + '.' + dir(sys)[each] + '.' + '__doc__'
> ## i cannot do
> print method.__doc__
> ## this doesn't evaluate method properly.
> ## Does eval work in this situation?
>
> Also, please, let me know if what I am trying to do is awkward way of
> doing it. How does Python approach such evaluation.
import sys
for each in dir(sys):
try:
print '%s: %s' % (each, getattr(sys, each).__doc__)
print
except AttributeError:
print
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list