On Fri, 02 Nov 2007 16:39:12 +0000, Roberto Bonvallet wrote:
> On 31 oct, 22:21, Paul Rubin <http://[EMAIL PROTECTED]> wrote:
>> def convert(n):
>> assert type(n) in (int,long)
>
> I'd replace this line with n = int(n), more in the spirit of duck
> typing.
Not necessarily. Something duck typing is too liberal in what it accepts.
You might want convert(math.pi) to raise an exception, although I'd
suggestion an assert is the wrong test. A better test would be an
explicit type check with raise:
if not isinstance(n, (int, long)):
raise TypeError('n not an integer')
assert is for "this can never happen" tests rather than type checking.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list