[Tutor] Decision matrix

Erik Price erikprice@mac.com
Thu Feb 13 22:20:03 2003


On Thursday, February 13, 2003, at 08:03  PM, Jeff Shannon wrote:

> Yes.  Python has quite a number of informal protocols, and any object 
> that supports certain actions is said to conform to that protocol.  
> For instance, you'll find many references in the docs to "file-like 
> objects" -- Python doesn't care whether it's *actually* a file object 
> or not, as long as it has write(), read(), readlines() (and sometimes 
> seek() and tell(), etc) methods.  In fact, there's a library object 
> (StringIO) that wraps a file-like interface around a normal 
> (presumably long) string. There's also a sequence protocol, which 
> involves responding appropriately to indexing, slicing, iteration, and 
> the like.  You can even write your own sequences -- just create a 
> class that defines __getitem__(), __setitem__(), __len__(), etc. -- 
> just as you can write your own file-like objects and your own 
> dict-like objects.

I see.  So these are protocols that have come up via convention, i.e. 
there is no standard by which to implement the protocol?  They have 
just come about from familiarity?

Or is there somewhere in the StdLib that specifies how implementations 
of, say, file-like objects should behave.


Erik





-- 
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org