"perl -p -i -e" trick in Python?

Stephen Thorne stephen.thorne at gmail.com
Wed Feb 16 01:38:03 EST 2005


On Wed, 16 Feb 2005 15:18:57 +0900, Wonjae Lee <shotgunlee at hotmail.com> wrote:
> I read the comment of
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277753.
> (Title : Find and replace string in all files in a directory)
> 
> "perl -p -i -e 's/change this/..to this/g'" trick looks handy.
> Does Python have a similar trick? Or, is there a shorter Python recipe for
> the given problem?

sure.

python -c 'import os; os.system("sed -i s/change this/...tothis/g")'

Using-the-right-tool-for-the-job-ly-y'rs
Stephen



More information about the Python-list mailing list