发布时间:2019-08-28 09:10:14编辑:auto阅读(2709)
#!/usr/bin/env python
#_*_coding:utf-8 _*_
#replace()方法把字符串中的 old(旧字符串)替换成new(新字符串),如果指定第三个参数max,则替换不超过 max 次。
#语法:str.replace(old, new[, max])
import sys,os
old_text, new_text, file_name = sys.argv[1], sys.argv[2], sys.argv[3]
f = file(file_name,'rb')
new_file = file('%s.bak' % file_name,'wb')
for line in f.xreadlines():
new_file.write(line.replace(old_text,new_text))
f.close()
new_file.close()重要说明 sys.argv[1] #参数1 sys.argv[2] #参数2 sys.argv[3] #参数3 #replace()方法把字符串中的 old(旧字符串)替换成new(新字符串),如果指定第三个参数max,则替换不超过 max 次。 #语法:str.replace(old, new[, max]) 使用方法: python code2.py ‘原始字符串’ ‘新字符串’ 文件
上一篇: Python基础:网络编程socket基
下一篇: python 如何引用上级目录的模块
51122
50515
41134
37976
32442
29344
28216
23059
23028
21351
1387°
2082°
1737°
1664°
1954°
1739°
2411°
4068°
3945°
2819°