Decorators using instance variables

robert2821 robert2821 at
Fri Aug 22 04:22:15 CEST 2008


I'm new; greetings all!

I'm wondering if the following program should work.  I think it should 
print 'Hello, World', but instead it produces a TypeError.  Is this a 
bug in decorators, a feature of them, or a mistake or misunderstanding 
on my part?

TIA,  Bob

def    getdec (f):
    dec = decorator (f)
    return dec. docall

class    decorator:

    def __init__ (self, f):
        self. f = f

    def docall (self, *a):
        return self. f (*a)

class    test:
    @ getdec
    def doit (self, message):
        print message

if __name__ == '__main__':
    foo = test ()
    foo. doit ('Hello, world')

-------------- next part --------------
A non-text attachment was scrubbed...
Type: text/x-python
Size: 327 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list