发布时间:2019-07-16 10:09:38编辑:auto阅读(1815)
[root@localhost ~]# less txt
123 345 678
accdfesdfdsf
[root@localhost ~]# less tihuan.py
#!/usr/bin/env python
import re
wenjian = open('txt','r+')
a = wenjian.read()
wenjian.seek(0,0)
f = (r'123')
b =re.findall(f,a)
if b != []:
wenjian.write(a.replace(f,'zzh'))
wenjian.close()
[root@localhost ~]# ./tihuan.py
[root@localhost ~]# less txt
zzh 345 678
accdfesdfdsf
上一篇: Python break 语句及与con
下一篇: python模块--random
48102
46789
37711
35037
29576
26237
25166
20203
19841
18315
5988°
6672°
6164°
6153°
7264°
6103°
6212°
6684°
6649°
8040°