print , (was Re: Python vs. Perl, which is better to learn?)

Aahz aahz at pythoncraft.com
Thu May 2 19:46:43 EDT 2002


In article <QSiA8.40950$8D3.1200259 at news1.tin.it>,
Alex Martelli  <aleax at aleax.it> wrote:
>Aahz wrote:
>>Alex:
>>>
>>>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$

<blink>  Learn something new every frickin' day.  I was not familiar with
this extra cute magic behavior of "print ," at the end of a line.  I
guess I like it, but I'm still a bit suspicious for no reason -- I think
I got confused way back when I was first learning Python and got the
double-spaced output of regular print, assuming that a space still got
stuck at the end of a line with "print ,", and never actually trying it.

Let this be a lesson to you newbies.  ;-)  (But I have no clue what
lesson it should be...)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I used to have a .sig but I found it impossible to please everyone..."  --SFJ



More information about the Python-list mailing list