The term "Protocol"

Phil Frost indigo at bitglue.com
Sun Aug 1 21:41:30 EDT 2004


"Protocol" in python has no meaning beyond normal English. Specifically
the iteration protocol says the iterable must have a __iter__ method
which returns an object that has an __iter__ which returns self, and a
next() method that returns the next thing in the thing being iterated.
When there are no more things, next() raises StopIteration. All of this
is a simple protocol defined by the python language. It doesn't
introduce anything new to the language besides the protocol itself;
__iter__ and next are regular methods and StopIteration is raised just
as any other class can be raised as an exception.

On Sun, Aug 01, 2004 at 07:25:23PM -0600, Bruce Eckel wrote:
> Sunday, August 1, 2004, 6:51:15 PM, Tim Peters wrote:
> 
> > Iteration is a protocol, not a type.
> 
> I know the term "protocol" has been used to describe a language
> feature in a number of languages, but since we have no official
> "protocol" support in Python I'm interested in what "we" mean by this
> term. I'm going to guess that a protocol is like an interface in Java,
> except that it doesn't have a concrete definition anywhere, but it is
> implied through convention and use. Thus a protocol is a "latent
> interface." Am I close? I'd like to understand this term better.
> 
> Bruce Eckel



More information about the Python-list mailing list