Why we will use obj$func() often

Mark Hahn mark at prothon.org
Fri Apr 23 17:00:03 EDT 2004


"Mel Wilson" <mwilson at the-wire.com> wrote ...

>     connection = serial.Serial ( ... )
>         # connection is a file-like object,
>         # having the usual `write` method
>
>     engine = MyFiniteStateMachine ()
>         # engine happens to have a `writer` method that
>         # funnels out the machines products
>         # The default is effectively `def writer (self, s): print s`
>
>     engine.writer = connection.write
>         # we channel engine's output through the serial connection
>
>    Plugged together, it just works, as Mike says.  No
> trouble when engine's internal calls to `self.writer` end up
> accessing a completely different object's method.  It's only
> lately that I've stopped to gawp at it, and wonder.

That is a powerful testimonial to the "walks like a duck" principal which
has nothing to do with classes or prototypes.  Thankfully that works in a
simple classless language like the current Prothon.





More information about the Python-list mailing list