def classDecorator(aClass):
def variables(self):
for variable in self.__dict__:
if isinstance(variable, int):
yield variable
setattr(aClass, 'variables', variables)
return aClass
@classDecorator
class myClass:
pass
if __name__ == '__main__':
x = myClass()
x.a = 2
print(str(x.variables()))
This decorator should add a method to the class that returns an iterator of the instance variables of type int of the instance it is invoked by, but if I run the program it prints this:
<generator object classDecorator.<locals>.variables at 0x011385D8>
Why?