Decorating instance methods

Cousin Stanley cousinstanley at hotmail.com
Mon Jul 9 21:47:06 CEST 2007


> ....
> Try this:
> ....

  Sesame  __Street__  Version ....

'''
    NewsGroup .... comp.lang.python
    Subject ...... Decorating instance methods
    Post_By ...... Alexander Draeger
    Reply_By ..... Duncan Booth
    Edit_By ...... Stanley C. Kitching
'''

def logging( f ) :

    def deco( self , *args , **kw ) :

        print "    %s in da house !" % self.name 
        return f( self , *args , **kw )

    return deco


class A( object ) :

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

    @logging
    def hello( self ) :
        print '    Yo, %s .... \n' % self.name


def test_01() :

    print

    list_names   = [ 'Bert' , 'Cookie Monster' , 
                     'Count Dracula' , 'Ernie' ]

    list_objects = [ A( this_name ) for this_name in list_names ]

    for this_object in list_objects :
        this_object.hello()


if __name__ == '__main__' :

    test_01()


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----



More information about the Python-list mailing list