You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Ben Collins-Sussman <su...@collab.net> on 2002/06/04 21:30:04 UTC

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

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'?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

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

Posted by Greg Stein <gs...@lyra.org>.
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

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

Posted by Branko Čibej <br...@xbc.nu>.
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.  :-)
>
Yep, I fixed that. :-)
(I also managed to break my commits-per-second record by not reading 
what I wrote. :-( )

>Is sys.stdout.write() better than 'print'?
>  
>
It comes to the same thing in the end. 'print' is a keyword, so you 
can't use it in 'map, but it uses whatever object is hidden in sys.stdout.

-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org