I want to make a registry of methods of a class during creation. My
attempt was this
""" classdecorators .py
Author: Justin Bayer
Creation Date: 2006-06-22
Copyright (c) 2006 Chess Pattern Soft,
All rights reserved. """
class decorated(objec t):
methods = []
@classmethod
def collect_methods (cls, method):
cls.methods.app end(method.__na me__)
return method
class dec2(decorated) :
@collect_method s
def first_func(self ):
pass
@collect_method s
def second_func(sel f):
pass
def main():
print dec2.methods
if __name__ == '__main__':
main()
This does not work and exits with "NameError: ("name 'collect_method s'
is not defined",)". Which is understandable due to the fact that the
class dec2 is not complete.
Anyone can give me a hint how to work around this?
attempt was this
""" classdecorators .py
Author: Justin Bayer
Creation Date: 2006-06-22
Copyright (c) 2006 Chess Pattern Soft,
All rights reserved. """
class decorated(objec t):
methods = []
@classmethod
def collect_methods (cls, method):
cls.methods.app end(method.__na me__)
return method
class dec2(decorated) :
@collect_method s
def first_func(self ):
pass
@collect_method s
def second_func(sel f):
pass
def main():
print dec2.methods
if __name__ == '__main__':
main()
This does not work and exits with "NameError: ("name 'collect_method s'
is not defined",)". Which is understandable due to the fact that the
class dec2 is not complete.
Anyone can give me a hint how to work around this?
Comment