[Tutor] How do I iterate through object attributes

Tim Johnson tim@johnsons-web.com
Sun, 4 Feb 2001 12:54:40 -0900


Newbie question here:
I would like to be able to iterate through a function's attributes and return
values for them: Code is below:
def f():
	"f() doc string"
	z = 720
	x = 840
f_dir =  dir(f)
print "f() attributes:",f_dir
f_attr = f_dir[0]
print "first attribute:", f_attr
print f.__doc__
for attr in f_dir:
	print attr
	#print f.attr   #This Code generates AttributeError

To restate: How may I reference the value for one member of
the attribute list of a function without the literal name of that attribute.

I hope I'm phrasing this question properly.
TIA
 --
Tim Johnson
-----------
"Of all manifestations of power,
 restraint impresses the most."
 -Thucydides