with open ("1.txt","r") as f:
data = f.readlines()
with open ("1_A.txt","w") as f:
for d in data:
items = d.split("=")
print(items)
if len(items)>1:
f.write("{}\n".format(items[-1].strip()))
1、读取txt文件,然后使用split函数,讲每行内容进行切分;
2、切分后的文件写入新的文件。
代码参考:
ls=[]
with open('test.txt') as f:
for t in f.readlines():
s = t.strip().split('=')[-1]
ls.append(s)
with open('new.txt','a+') as f1:
for i in ls:
f1.write(i)
f1.write('\n')
a="42-22==20vk"
a.rfind("=")
6
a[a.rfind("=")+1:]
'20vk'