some random reflections of a "Python newbie": (2) language issues

skaller skaller at maxtal.com.au
Thu Dec 16 15:37:04 EST 1999


Alex Martelli wrote:
> 
> John Skaller writes (and I focus on my sole
> disagreement with his long fascinating post):
>     [big snip]
> > > how to prototype in Python-as-it-stands
> > > (not with the needed polymorphism, and
> > > good performance, etc, which are the
> > > whole point of the suggestion:-).
> >
> > The answer is to use named methods, like:
> >
> > x.contains(y)
> >
> > This works, even if the syntax is not
> > exactly what you want. And it is safer, since it
> 
> Nope, this gives no _polymorphism_ whatsoever.

That's not quite correct. It is correct to say that
this will not work with _existing_ objects,
such as PyTuples.

But using the 'contains' method as illustrated
is every bit as polymorphic: it works for every
object providing a 'contains' method, just as

	y in x

works for every object providing a __contains__
method (or the C equivalent, which is a slot
filled in a type objects vtable).

The _only_ difference is syntax (which is not unimportant).

-- 
John Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850



More information about the Python-list mailing list