擅长:python、mysql、java
<p>试试这个。你知道吗</p>
<pre><code>import re
def replaceAll(file,searchExp,replaceExp):
for line in file.readlines():
try:
line = line.replace(re.findall(searchExp,line)[0],replaceExp)
except:
pass
sys.stdout.write(line)
#following code is not working, i expect to list out the files start #with "um_*.txt", open the file & replace the "$$\d" with replaceAll function.
for um_file in glob.glob('*.txt'):
t = open(um_file, 'r')
replaceAll(t,"\d+","xxx")
t.close()
</code></pre>
<p>这里我们将文件处理程序发送到<code>replaceAll</code>函数,而不是字符串。你知道吗</p>