group several methods under a attribute

jelle jelleferinga at gmail.com
Mon Apr 6 15:52:50 EDT 2009


Hi Aaron,

Thanks a lot for your suggestions.
I wasnt familiar with the __get__ magic, which seems interesting.

So, finally it seems that the cleanest pattern is:

class ClsA( object ):
    def __init__( self, other ):
        self.inst= other

    def submethA( self, arg ):
        print( 'submethA %r, instance %r'% ( arg, self.inst ) )

class ClsB( object ):
    def methA( self, arg ):
        self.A= ClsA( self )
        print( 'methA %r'% arg )

b= ClsB( )
b.methA( 'this' )
b.A.submethA( 'that' )


Many thanks,


-jelle





More information about the Python-list mailing list