您的位置:首页 > 编程语言 > Python开发

python 替换文件固定字符串

2016-08-02 19:10 211 查看
try:
fo = open(file_path, "r+")
lines = fo.readlines()

fo.seek(0)
fo.truncate()
for line in lines:
fo.write(line.replace(old, new))
fo.close()
return 1
except Exception,e:
print e
return 0

seek 回到文件开
truncate 清空文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: