polymorphism (was Re: Type checking in python?)

Shae Erisson shapr at uab.edu
Wed Jul 26 16:54:52 EDT 2000


Donn Cave wrote:

> Or you can simply expect a read() method.  Don't verify it, don't
> support anything else.  The polymorphism is up to the caller.  Examples
> of this with the file interface can be found in the library, rfc822 comes
> to mind.  I think this is more common than checking for method attributes
> and then supporting different interfaces.

According to all the Python lore/attitude/community feeling/etc that
I've absorbed, that's the way to do it.
This way you know you can interact with a file object, and any other
object that wants to act like a file object.
Interface does seem to be very important in the standard libraries, but
type does not seem to be anywhere close in importance.
Many of the standard libs support 'any object that has a "read" method
like a file object."
-- 
Shae Matijs Erisson - http://www.webwitches.com/~shae/
VirtualPairProgramming Wanted - Linux/Emacs/Python/Speak Freely
.fi: rakastan ohjelmointia - python kengittää aasia



More information about the Python-list mailing list