Binding? problem

Scott David Daniels Scott.Daniels at Acm.Org
Sun Sep 12 15:46:40 EDT 2004


Josh English wrote:
> I'm working on a Stack based language that can import methods from 
> predefined libraries. Here's what I mean....
> 
Tell us more about the problem you are trying to solve.  Normally you'd
do this on classes.  Why doesn't this work?:

     class S(object):
         def __init__(self, value):
             self.value = value

         def __repr__(self):
             return '%s(%r)' % (self.__class__.__name__, self.value)

     class Mixin_do_this(object):
         def do_this(self):
             self.s.value = 'this'

     class Runner(object):
         def __init__(self):
             self.s = S('whock')

         def __repr__(self):
             # self.s below, not self.S
             return '<%s %s>' % (self.__class__.__name__, self.s)

     class Runner2(Runner, Mixin_do_this): pass

     r2 = Runner2()
     print r2
     r2.do_this()
     print r2

-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list