perl -pi.bak -e equivalent
Diez B. Roggisch
deetsNOSPAM at web.de
Sat Nov 20 08:28:12 EST 2004
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...
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list