[Python-3000] Python 3000 Status Update (Long!)

Nick Coghlan ncoghlan at gmail.com
Wed Jun 20 16:44:10 CEST 2007


Nicko van Someren wrote:
> 	>>> sum(['a','b','c'])
> 	Traceback (most recent call last):
> 	  File "<stdin>", line 1, in <module>
> 	TypeError: unsupported operand type(s) for +: 'int' and 'str'
> 	>>> sum([["a"],[u'b'],[3]])
> 	Traceback (most recent call last):
> 	  File "<stdin>", line 1, in <module>
> 	TypeError: unsupported operand type(s) for +: 'int' and 'list'

You can already make the second example work properly by supplying an 
appropriate starting value:

 >>> sum([["a"],[u'b'],[3]], [])
['a', u'b', 3]

(and a similar call will also work for the new bytes type, as well as 
other sequences)

Strings are explicitly disallowed (because Guido doesn't want a second 
way to spell ''.join(seq), as far as I know):

 >>> sum(['a','b','c'], '')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: sum() can't sum strings [use ''.join(seq) instead]

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list