Python vs. Perl, which is better to learn?

Alex Martelli aleax at aleax.it
Thu May 2 18:14:08 EDT 2002


Aahz wrote:

>>for line in fileinput.input():
>>    if there.search(line): print line,
> 
> Thanks!  I don't really like "print line,", because it adds an extra
> space that wasn't there before, 

Where do you think it adds that space...?

[alex at lancelot indomo]$ cat -E prova
uno due tre$
sei due cinque$
palik palok$
tre due uno$
[alex at lancelot indomo]$ python mygrep.py due prova | cat -E
uno due tre$
sei due cinque$
tre due uno$
[alex at lancelot indomo]$

> so I prefer sys.stdout.write().  It's a matter of taste, though.

I like sys.stdout.write, too, but I'm still perplexed by the "adds an
extra space that wasn't there before" assertion.  You *are*
familiar with print's "softspace" mechanism, surely?  Is there
some peculiar corner case that I'm failing to think of...?


Alex





More information about the Python-list mailing list