writeln? (was Re: [Python-Dev] Idea - place to put string functions and consts)

John Machin sjmachin@lexicon.net
Tue, 19 Mar 2002 08:45:55 +1000


On 18 Mar 2002 at 16:11, Guido van Rossum wrote:

> > >>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
> > 
> >     >> COMMA.join(['spam', 'eggs'])
> > 
> >     GvR> This I've never liked.
> > 
> >     >> comma_join(['spam', 'eggs'])
> > 
> >     GvR> But this one's sweet!
> > 
> > Ah, so is it the uppercase letters or the dot you dislike <wink>?
> 
> Maybe that, maybe the bother of defining a name for a simple constant;
> it's not like you plan to ever change the program to give COMMA a
> different value.  But comma_join is sweet because it removes a constant
> evaluation from a loop (if the join occurs in a loop).

... like once per record when writing a huge file -- unless you are doing it in a C 
extension so that (inter alia) you can cheaply append "\n" while you are at it.

How come python hasn't grown a writeln method, as in:
   def writeln(self, s): self.write(s + "\n")
but implemented efficiently?

That
if (append_newline) *output++ = '\n';
just has to be up there with the all-time-best-bangs-per-LOC contenders.