Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You still have to explicitly pass a `this` to that function, which is kind of my earmark for telling methods and functions apart. (In this regard, Python treads a fine line where it has an explicit `self` parameter that is passed in automatically).


You can manually pass in the `self` parameter to unbound methods if you like.

    import itertools

    class Test():
        def __init__( self, number ):
            self._number = number
            return

        def aaa( self ):
            print 'AAA<%s>' % str( self._number )
            return

        def bbb( self ):
            print 'BBB<%s>' % str( self._number )

    def main():
        instances = [ Test( n ) for n in range( 100 ) ]
        functions = [ Test.aaa, Test.bbb ]

        for instance, function in zip( instances, itertools.cycle( functions ) ):
            function( instance )

    if __name__ == '__main__':
        main()




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: