[issue20959] print gives wrong error when printing *generator

Jurjen N.E. Bos report at bugs.python.org
Mon Mar 17 15:17:49 CET 2014


New submission from Jurjen N.E. Bos:

One of the more interesting ways to use print is printing output of a generator, as print(*generator()).
But if the generator generates a typeError, you get a very unhelpful error message:
>>> #the way it works OK
>>> def f(): yield 'a'+'b'
...
>>> print(*f())
ab
>>> #Now with a type error
>>> def f(): yield 'a'+5
...
>>> print(*f())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: print() argument after * must be a sequence, not generator

The problem is twofold:
- the message is plainly wrong, since it does work with a generator
- the actual error is hidden from view

----------
components: IO
messages: 213869
nosy: jneb
priority: normal
severity: normal
status: open
title: print gives wrong error when printing *generator
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20959>
_______________________________________


More information about the Python-bugs-list mailing list