On Tue, May 09, 2006 at 10:31:02PM +0200, tomer filiba wrote:
> i.e., "is the object addable?" == "hasattr(obj, '__add__')".
Even this is meaningless: '1'+1. So duck typing is:
try:
return a+b
except TypeError:
return "Oops..."
> iterable_protocol = ["__iter__"]
> sequence_protocol = ["__getitem__", "__setitem__",
> "__contains__", "__iter__"]
A read-only sequence could lack __setitem__().
> file_protocol = ["write", "read", "close", "fileno"]
StringIO lacks fileno() so it is not a file-like object, is it?
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED]
Programmers don't die, they just GOSUB without RETURN.
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com