PEP 259: Omit printing newline after newline
Alex Martelli
aleaxit at yahoo.com
Tue Jun 12 09:56:26 EDT 2001
"Marcin 'Qrczak' Kowalczyk" <qrczak at knm.org.pl> wrote in message
news:slrn.pl.9ibh7p.2gn.qrczak at qrnik.zagroda...
> 11 Jun 2001 17:47:12 -0400, Andrew Kuchling <akuchlin at mems-exchange.org>
pisze:
>
> > -1; I'd rather see a strip_trailing_whitespace argument added to
> > .readlines(), or some alternative idiom encouraged that sidesteps the
> > issue. Magical behaviour is bad.
>
> print is too magic in the first place. I would rather add write
> builtin function, equivalent to sys.stdout.write, and arrange that
> write functions are easy to use, i.e. allow multiple arguments,
> apply str to them, and maybe have also writeln.
Same here, except I don't think "write" is the best name (I'd
prefer for example "output", but I consider that minor) AND I
don't think two functions are ideal -- rather, one function
with a named parameter ln=1 (by default). I.e., where your
suggestions might let one code:
write(a,b,c)
writeln(d,e,f)
I'd rather express it:
output(a,b,c,ln=0)
output(d,e,f)
(np for me if ln defaults the other way, or is called in
some other fashion). But the differences between your
ideas and mine are basically syntax-sugar.
Besides several advantages for having this stuff in a function,
which I have already mentioned, consider:
output(a,b,*manymore)
versus... what?
print a,b,
for item in manymore:
print item,
print
How's that for a statement's "convenience"?-)
Having the newline/nonewline choice in a named parameter
rather than in two different functions (or syntax forms
right now) is a tad more than just sugar:
def linend(i, longish=longish):
return i==len(longish)-1 or i%10==9
# print no more than 10 per line
for i in range(len(longish)):
print longish[i],
if linend(i):
print
or
# print no more than 10 per line
for i in range(len(longish)):
write(longish[i])
if linend(i):
writeln()
vs
# print no more than 10 per line
for i in range(len(longish)):
output(longish[i], ln=linend(i))
Alex
More information about the Python-list
mailing list