iterate over class variables

Yves Glodt y.glodt at sitasoftware.lu
Thu Nov 10 07:04:55 EST 2005


Hello list,

I need to iterate over a class and get all her variable names and 
values, e.g. considering this example:


class testclass:
	var1 = 'ab'
	var2 = 'cd'
	var3 = 'ef'

test = testclass()



Then I wanna do sonmething like this:

for name,value in test:
	print name
	print value

fails with of course with:
"TypeError: iteration over non-sequence"


How can I do that?

regards,
Yves



More information about the Python-list mailing list