fadder
February 17th, 2007, 11:51 AM
Hi,
I'm trying to learn python, starting from a perl background. I'd like to do the
equivalent to the following perl code:
foreach $i ( 23, 45, 67 ) {
open(IN,"<file$i.dat");
or,
system(" do-something-with-$i ")
}
So that $i is replaced by relevent numbers. I know that in python I could do something
like f="file%d.dat" % i and then open that file on another line, but is there a way
to do this in-place? I am so used to perl's usage where I can subtitute anything anywhere i a string.
Thanks for any tips.
I'm trying to learn python, starting from a perl background. I'd like to do the
equivalent to the following perl code:
foreach $i ( 23, 45, 67 ) {
open(IN,"<file$i.dat");
or,
system(" do-something-with-$i ")
}
So that $i is replaced by relevent numbers. I know that in python I could do something
like f="file%d.dat" % i and then open that file on another line, but is there a way
to do this in-place? I am so used to perl's usage where I can subtitute anything anywhere i a string.
Thanks for any tips.