Decorators using instance variables

robert2821 robert2821 at verizon.net
Thu Aug 21 22:22:15 EDT 2008


Hi,

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...
Name: Dec.py
Type: text/x-python
Size: 327 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20080821/40bc63df/attachment.py>


More information about the Python-list mailing list