python equivalent to perl's inplace edit mechanism

Michael Mabin d3vvnull at gmail.com
Thu May 8 08:11:56 EDT 2008


Does python have an equivalent to Perl's inplace-edit variable $^I?
For example, the following perl code below changes mike to dave in a file
that is passed as an argument.

#!/usr/bin/env perl
#chgit script
$^I = '';
while(<>) {
  s/mike/dave/g;
  print;
}

The script would be used as below:
chgit somefile

Afterward, all instances of mike are changed to dave.

Thanks.

Mike

-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080508/6948cfc2/attachment.html>


More information about the Python-list mailing list