新手刚学py,参考了一下大佬的代码,结合自己的想法写的查找txt文件方法。
旨在记录每天学习的内容
def copyChun():
# with open(file="dict.txt",mode="r",encoding=utf8) as afile:
s = "风"
print("Loading...")
with open(file=r"全唐诗.txt",mode='r',encoding='utf8') as srcfile:
for line in srcfile:
str = srcfile.readline()
if s in str:
with open(file=r"风.txt",mode="a",encoding='utf8') as dstfile:
dstfile.write(str)
dstfile.close()
# else:
# print("这行没有正在跳转下一行")
def copyYv():
s = "雨"
print("Loading...")
with open(file=r"全唐诗.txt",mode='r',encoding='utf8') as srcfile:
for line in srcfile:
str = srcfile.readline()
if s in str:
with open(file=r"雨.txt",mode="a",encoding='utf8') as dstfile:
dstfile.write(str)
dstfile.close()
# else:
# print("这行没有正在跳转下一行")
s = "润物"
print("Loading...")
with open(file=r"全唐诗.txt",mode='r',encoding='utf8') as srcfile:
for line in srcfile:
str = srcfile.readline()
if s in str:
with open(file=r"雨.txt",mode="a",encoding='utf8') as dstfile:
dstfile.write(str)
dstfile.close()
copyChun()
copyYv()