evaluate a variable
ignacio at openservices.net
Fri Sep 14 15:57:18 CEST 2001
On Fri, 14 Sep 2001 dimitry_snezhkov at yahoo.com wrote:
> I just started learning Python. Of, course , reading output of
> 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.
for each in dir(sys):
print '%s: %s' % (each, getattr(sys, each).__doc__)
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list