Registry of Methods via Decorators

bayerj bayerj at
Thu Jun 22 15:32:25 CEST 2006

I want to make a registry of methods of a class during creation. My
attempt was this


Author: Justin Bayer
Creation Date: 2006-06-22
Copyright (c) 2006 Chess Pattern Soft,
All rights reserved.  """

class decorated(object):

    methods = []

    def collect_methods(cls, method):
        return method

class dec2(decorated):

    def first_func(self):

    def second_func(self):

def main():
    print dec2.methods

if __name__ == '__main__':

This does not work and exits with "NameError: ("name 'collect_methods'
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?

More information about the Python-list mailing list