import osgeci=open("a.txt",encoding="utf-8")new_geci=open("a1.txt","w",encoding="utf-8")for line in geci: change=line.replace("一","1") new_geci.write(change)geci.close()new_geci.close()os.remove("a.txt")os.rename("a1.txt","a.txt")with 方法执行关闭
import osgeci=open("a.txt",encoding="utf-8")new_geci=open("a1.txt","w",encoding="utf-8")with open("a.txt",encoding="utf-8")as geci,open("a1.txt","w",encoding="utf-8")as new_geci: for line in geci: change=line.replace("一","1") new_geci.write(change)
os.remove("a.txt")os.rename("a1.txt","a.txt")
文件a.txt
歌曲:《开心每1天》作词:刘顶柱演唱:李淑英背景音乐歌词:开心每1天 快乐每1天开心每1天 快乐每1天开心每1天 快乐每1天开心那每1天阳光温暖天空蔚蓝彩云编织霓虹的光环溪水清亮空气新鲜青草铺开绿色生态园人生多美好呀人心多么善好风好雨好消息吻上我的脸世界多么大呀天地多么宽好山好水好风景美丽我心田
转载于:https://www.cnblogs.com/fandonghua/p/11586607.html