Re: iterate over class variables

2005-11-10 Thread Yves Glodt
bruno at modulix wrote: > Yves Glodt wrote: >> Yves Glodt wrote: >> >>> 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' > > Take

Re: iterate over class variables

2005-11-10 Thread Peter Hansen
Yves Glodt wrote: > 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' Is the following of any help to you? >>> class testclass: ... a = 'a' ... >>> dir(testcla

Re: iterate over class variables

2005-11-10 Thread bruno at modulix
Yves Glodt wrote: > Yves Glodt wrote: > >> 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' Take care, these are *class* variables, not i

Re: iterate over class variables

2005-11-10 Thread Daniel Evers
Hi! You can iterate over the internal dictionary: >>> class Test: ... def __init__(self): ... self.x = 5 ... self.y = 6 ... self.z = "Hallo" ... >>> x = Test() >>> print x.__dict__ {'y': 6, 'x': 5, 'z': 'Hallo'} >>> for key, value in x.__dict__.items(): ..

Re: iterate over class variables

2005-11-10 Thread Yves Glodt
Yves Glodt wrote: > Yves Glodt wrote: >> 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 w

Re: iterate over class variables

2005-11-10 Thread Yves Glodt
Yves Glodt wrote: > 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 th

iterate over class variables

2005-11-10 Thread Yves Glodt
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 n