http://www.bics.be.schule.de/inf2/programmiersprachen/python/oop2/patoop/index.html
http://www.oreilly.de/catalog/einpythonger/chapter/ch09.html
http://www.bics.be.schule.de/inf2/programmiersprachen/python/oop2/pyth3.html
http://www.bics.be.schule.de/inf2/programmiersprachen/python/oop2/index.html
1 import fileinput, glob, string, sys, os
2 from os.path import join
3 # replace a string in multiple files
4 #filesearch.py
5
6 if len(sys.argv) < 2:
7 print "usage: %s search_text replace_text directory" % os.path.basename(sys.argv[0])
8 sys.exit(0)
9
10 stext = sys.argv[1]
11 rtext = sys.argv[2]
12 if len(sys.argv) ==4:
13 path = join(sys.argv[3],"*")
14 else:
15 path = "*"
16
17 print "finding: " + stext + " replacing with: " + rtext + " in: " + path
18
19 files = glob.glob(path)
20 for line in fileinput.input(files,inplace=1):
21 lineno = 0
22 lineno = string.find(line, stext)
23 if lineno >0:
24 line =line.replace(stext, rtext)
25
26 sys.stdout.write(line)
| /Datentypen /Klassen /KontrollStrukturen |
Python/Sprache/KontrollStrukturen (last modified 2008-11-04 07:00:04)