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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4