list(), tuple() should not place at "Built-in functions" in documentation

Corey Richardson kb1pkl at aim.com
Sat Jul 16 03:50:10 EDT 2011


Excerpts from Inside's message of Sat Jul 16 01:40:21 -0400 2011:
> Supplement:
> The assertion will not be handled anyway.
> I want AssertionError raise as early as possible.(mentinoed before)

An AssertionError is pretty useless, there are much better exceptions
that you could (and should!) use, depending on the context. If you
need a sequence, just use it like it is. If it's not a sequence a 
TypeError will be raised anyway:

>>> class Foo(object): pass
... 
>>> f = Foo()
>>> for i in f: pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Foo' object is not iterable
>>> 

Which is tons more useful than

>>> assert isinstance(f, (list, tuple))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
>>> 
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
     -- Abraham Lincoln
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20110716/7482f0da/attachment-0001.sig>


More information about the Python-list mailing list