py3k printing generators -- not!

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Jun 6 14:59:39 CEST 2009


samwyse:
> 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))
    print(txt)

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

Bye,
bearophile



More information about the Python-list mailing list