shane at zope.com
Sat Jul 26 00:39:25 CEST 2003
Bjorn Pettersen wrote:
>>From: Shane Hathaway [mailto:shane at zope.com]
>>def foo(bar, baz):
>> assert isinstance(bar, int)
>> assert isinstance(baz, str)
> ...which means you can't use foo with unicode strings or UserStrings,
That's right, and that's intentional. The function is designed to work
only with byte arrays. This invites someone who wants to pass a unicode
object to first verify that the function will actually work properly
> etc., etc. This is C programming in Python, ugly, inefficient,
> inflexible, and un-Pythonic.
It is highly useful documentation. There is nothing inefficient about
it. It is as flexible as the programmer makes it. It is quite
Pythonic, although you should only declare the types of arguments when
the type matters.
I should say that in actual practice, I haven't used isinstance()
checks. Instead, I've been checking against Zope interfaces.
More information about the Python-list