diff --git a/diy2.py b/diy2.py index 63c94b1..6299ba8 100644 --- a/diy2.py +++ b/diy2.py @@ -1,4 +1,9 @@ with open(r"C:\Users\Administrator\Desktop\book.txt",'r',encoding='utf-8') as file: for data in file: if '小兰:12本' in data: - print('小兰数据在文件中') \ No newline at end of file + print('小兰数据在文件中') +with open(r"C:\Users\Administrator\Desktop\book.txt",'w',encoding='utf-8') as file: + file.write(new_data) +with open(r"C:\Users\Administrator\Desktop\book.txt",'r',encoding='utf-8') as file: + a = file.read() + print(a) \ No newline at end of file