r...@zedat.fu-berlin.de (Stefan Ram) writes: > Meredith Montgomery <mmontgom...@levado.to> writes: >>Is that at all possible somehow? Alternatively, how would you do your >>toy oop-system? > > Maybe something along those lines: > > from functools import partial > > def counter_create( object ): > object[ "n" ]= 0 > def counter_increment( object ): > object[ "n" ]+= 1 > def counter_value( object ): > return object[ "n" ] > > counter_class =( counter_create, counter_increment, counter_value ) > > def inherit_from( class_, target ): > class_[ 0 ]( target ) > for method in class_[ 1: ]: > target[ method.__name__ ]= partial( method, target ) > > car = dict() > > inherit_from( counter_class, car ) > > print( car[ "counter_value" ]() ) > car[ "counter_increment" ]() > print( car[ "counter_value" ]() ) > > . The "create" part is simplified. I just wanted to show how > to make methods like "counter_increment" act on the object > that inherited them using "partial".
That's simple and interesting. I'll study your more elaborate approach next, but I like what I see already. Thank you so much. -- https://mail.python.org/mailman/listinfo/python-list