(gulp) newbie question - portablity of python
nospam at sorry.com
Sun May 14 23:49:38 CEST 2000
Very nice of you to post that. Thank you.
Moshe Zadka <moshez at math.huji.ac.il> wrote in message
news:Pine.GSO.4.10.10005142328180.21724-100000 at sundial...
> On Sun, 14 May 2000, Keygrass wrote:
> > So ... my question is this: Is this really too good to be true?
> > Basically, I want a build a program that will replace words and number
> > another file. For example, if I had a file called "Outdoor_sports" that
> > contained the word "baseball bat", I would want my program to change it
> > it would say "football".
> Here it is, in its entirety.
> import string, sys
> def replace_word_in_file(file, word, replacement):
> f = open(file)
> s = f.read()
> s = string.replace(s, word, replacement)
> f = open(file, 'w')
> if __name__ == '__main__':
> if len(sys.argv) < 4:
> for file in sys.argv[3:]:
> replace_word_in_file(sys.argv, sys.argv, file)
> Save it as "replace.py", and it will work on pretty much anything.
> For 10 more minutes of work, you can also write a Tk GUI which will work
> on Windows an UNIX (and on MacOS, with a little coaxing)
> Moshe Zadka <moshez at math.huji.ac.il>
> http://www.linux.org.il -- we put the penguin in .com
More information about the Python-list