perl -pi.bak -e equivalent

gabriele renzi rff_rff at remove-yahoo.it
Sat Nov 20 09:53:06 EST 2004


Diez B. Roggisch ha scritto:

> Caj Zell wrote:
> 
> 
>>Hello,
>>
>>I am looking a little bit at python and am curious of one thing I
>>often use in perl. Suppose, I want to change the string
>>"best_composer" to "Zappa" in a document called facts.txt, then in
>>perl I would do
>>
>>perl -pi.bak  -e "s/best_composer/Zappa/;" facts.txt
>>
>>Can I do that with python from the command line so easily?
> 
> 
> Short answer: No. Perl is designed for this kind of stuff. Python won't
> catch up in that field, for various reasons. There have been plenty of
> discussions on the subject of one-liners in python - googl.groups will show
> you to them. 
> 
> As always, its important to use the right tool for the job - and in this
> case, I'd even go for sed :)
> 
> sed s/best_composer/Zappa/ < facts.txt > pi.bak
> 
> is even shorter...

let me suggest pyone:
http://www.unixuser.org/~euske/pyone/

It is really an erethic twist of python, anyway

PS
the perl code does not do the same thing than the sed one, it creates a 
backup file named facts.txt.bak and changes facts.txt




More information about the Python-list mailing list