[Python-Dev] Replacement for print in Python 3.0
Nick Coghlan
ncoghlan at gmail.com
Sun Sep 4 12:19:46 CEST 2005
Tony Meyer wrote:
> [Nick Coghlan]
>
>>"Print as statement" => printing sequences nicely is a pain
>
>
> What's wrong with this?
>
>
>>>>print range(10)
>
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>
>>>>print tuple("string")
>
> ('s', 't', 'r', 'i', 'n', 'g')
>
> This is a serious question - that's how I would expect a print function to
> work anyway.
Py> print (x*x for x in range(10))
<generator object at 0x00AE71C0>
Oh, wait, this is what I actually meant:
Py> print " ".join(map(str, (x*x for x in range(10))))
0 1 4 9 16 25 36 49 64 81
Printing the contents of an arbitrary iterable is harder than it should be.
Many iterables (including the builtin ones) have a reasonable default display,
but a non-default display (e.g. linefeed separated instead of comma separated)
isn't the most obvious thing to express.
I thought making print a function solved that problem, but it doesn't really.
So I'm currently exploring a different approach involving string formatting.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list