Python 官方文档:入门教程 => 点击学习
[root@localhost 1008]# cat test01.txt 1 3194 0 2013-11-15 19:25:471 696 0 2013-11-15 19:29:561
[root@localhost 1008]# cat test01.txt
1 3194 0 2013-11-15 19:25:47
1 696 0 2013-11-15 19:29:56
1 3194 0 2013-11-15 19:30:09
1 56 0 2013-11-15 19:30:25
1 1111 0 2013-11-15 19:31:41
1 56 0 2013-11-15 19:48:36
1 3160 0 2013-11-15 19:48:43
1 177 0 2013-11-15 19:48:50
1 3438 0 2013-11-15 19:49:02
1 118 0 2013-11-15 19:50:15
1 177 0 2013-11-15 19:50:34
1 3438 0 2013-11-15 19:50:38
#!/usr/bin/python
import fileinput
for line in fileinput.input('/script/Python/1008/test01.txt',inplace=1):
line = line.replace('2013-11-15','zhang')
print line,
1 3194 0 zhangxz 19:25:47
1 696 0 zhangxz 19:29:56
1 3194 0 zhangxz 19:30:09
1 56 0 zhangxz 19:30:25
1 1111 0 zhangxz 19:31:41
1 56 0 zhangxz 19:48:36
1 3160 0 zhangxz 19:48:43
1 177 0 zhangxz 19:48:50
1 3438 0 zhangxz 19:49:02
1 118 0 zhangxz 19:50:15
1 177 0 zhangxz 19:50:34
1 3438 0 zhangxz 19:50:38
--结束END--
本文标题: python文件全局替换
本文链接: https://lsjlt.com/news/188715.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0