py3k printing generators -- not!

bearophileHUGS at bearophileHUGS at
Sat Jun 6 14:59:39 CEST 2009

> Always saying "print(','.join(x))" gets tiresome in a hurry.  I've
> thought about defining my own function "prnt" that wraps print and
> fixes generators, but that requires me to get their type,

Why do you need to know their type?
Isn't something like this enough?

def pr(it):
    txt = "".join(map(str, it))

That little function can be improved in many ways.

> despite the claims of "help(type(x for x in range(0)))"
> cannot be found in builtins.

Python can yield mixed types (nearly never recommended):

def foo():
  yield 1
  yield "hello"
  yield 1.5


More information about the Python-list mailing list