I miswrote my question. But I still completely understand. What I really
wanted to know was whether there was something equivalent to how perl can
perform inplace edits of a file with something like the magic $^I variable.
I see from Gabriel that you can use the fileinput module to achieve thi
On Thu, May 8, 2008 at 2:11 PM, Michael Mabin <[EMAIL PROTECTED]> wrote:
> Does python have an equivalent to Perl's inplace-edit variable $^I?
>
I misread your question.
No, Python eschews magic characters and symbols. They make code ugly
and harder to read and maintain.
The first 3 lines of the
En Thu, 08 May 2008 09:11:56 -0300, Michael Mabin <[EMAIL PROTECTED]> escribió:
> 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
> #!/usr/bin/env perl
> #chgit script
> $^I = '';
> while(<>) {
> s/mike/dave/g;
> print;
> }
>
#!/usr/bin/python
import sys
lines = open(sys.argv[1]).readlines()
open(sys.argv[1], 'w').writelines([line.replace('mike', 'dave') for
line in lines])
--
http://mail.python.org/mailman/listinfo/pyth
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