[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: rev 2081 - trunk/subversion/tests/clients/cmdline/svntest

From: Greg Stein <gstein_at_lyra.org>
Date: 2002-06-04 23:42:06 CEST

On Tue, Jun 04, 2002 at 04:30:04PM -0500, Ben Collins-Sussman wrote:
> brane@tigris.org writes:
> > Now make this look like Python, not C. :-)
> >
> > if (not error_expected) and (stderr_lines):
> > - for line in stderr_lines:
> > - print line,
> > + map(lambda x: sys.stdout.write(x), lines)
>
> Funny, that looks more like Lisp to me. :-)
>
> Is sys.stdout.write() better than 'print'?

'print' will add a newline at the end of the line. You "worked around it" by
adding the trailing comma. I don't recall the *exact* space-insertion
semantics, but that trailing comma could potentially have added a space,
too. In this particular situation, sys.stdout.write is probably a bit more
appropriate because it don't have any of the funny newline stuff -- it just
copies the input straight to the stdout.

However, Branko's statement about "look like Python" wasn't entirely
accurate. In general, using map when a simple for-loop will do is
discouraged. The problem with map() is that a function call to the lambda is
performed for each iteration; in Python, function calls are one of *the*
most expensive operations.

In Branko's second update, where he mapped using the sys.stdout.write
itself, is actually quite nice: you don't get an extra function call
overhead, and the loop iteration occurs purely in C code.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jun 5 00:23:26 2002

This is an archived mail posted to the Subversion Dev mailing list.