Phillip J. Eby wrote: > At 11:02 AM 9/3/2005 +1000, Nick Coghlan wrote: > >> Printing the items in a sequence also becomes straightforward: >> >> print " ".join(map(str, range(10))) => output(*range(10)) >> >> Playing well with generator expressions comes for free, too: >> >> print " ".join(str(x*x) for x in range(10)) >> => output(*(x*x for x in range(10))) > > > An implementation issue: that generator expression will get expanded > into a tuple, so you shouldn't use that for outputting large sequences.
Agreed - but using join with print suffers from a similar problem, in that it builds the large string in memory before displaying it. I actually hope that extended function call syntax in Py3k will use iterators rather than tuples so that this problem goes away. > I don't much care for 'output' as the name, or 'end' as the end-of-line > arguments, but for the most part I like the semantics; being able to > drop the separator or change the end-of-line string make lots of use > cases straightforward, and perhaps almost worth the parentheses. > > My inclination would be to call the function 'print', though, and rename > 'end' to 'trailer'. 'print' is Py24 incompatible though, which is why I didn't use it for the sample code. The version I put on the wiki now uses 'term' for the line terminator keyword, but I'm not too worried about the exact names at this point. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com