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
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
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
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():
..
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
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
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