Message20139
For str.join(), if it is passed an iterator and that
iterator raises a TypeError, that exception is caught
by the join method and replaced by its own
TypeError exception. SyntaxError and IndexError
exceptions are uneffected.
Example:
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC
v.1200 32 bit (Intel)] on win32
...
IDLE 1.0.2
>>> def gen(n):
if not isinstance(n, int):
raise TypeError, "gen() TypeError"
if n<0:
raise IndexError, "gen()
IndexError"
for i in range(n):
yield str(i)
>>> ''.join(gen(5))
'01234'
>>> ''.join(gen(-1))
Traceback (most recent call last):
File "<pyshell#9>", line 1, in -toplevel-
''.join(gen(-1))
File "<pyshell#7>", line 5, in gen
raise IndexError, "gen() IndexError"
IndexError: gen() IndexError
>>> ''.join(gen(None))
Traceback (most recent call last):
File "<pyshell#10>", line 1, in -toplevel-
''.join(gen(None))
TypeError: sequence expected, generator found
>>>
|
|
Date |
User |
Action |
Args |
2007-08-23 14:20:14 | admin | link | issue905389 messages |
2007-08-23 14:20:14 | admin | create | |
|