Commit 85e494b5 by BellCodeEditor

save project

parent 0aa543cb
Showing with 5 additions and 2 deletions
...@@ -5,16 +5,19 @@ ...@@ -5,16 +5,19 @@
# file1.write('小方:5本') # file1.write('小方:5本')
# file1.write('小高:20本') # file1.write('小高:20本')
# file1.close() # file1.close()
new_data=
with open(r'C:\users\CM\Desktop\test.txt','r',encoding='utf-8') as file1: with open(r'C:\users\CM\Desktop\test.txt','r',encoding='utf-8') as file1:
for data in file1: for data in file1:
if'小兰:12本' in data: if'小兰:12本' in data:
data=data.replace('小兰:12本','小兰:14本')
new_data+=data
print('数据在文件中') print('数据在文件中')
file1.write('小兰:12本') file1.write('小兰:12本')
a=file.read() a=file.read()
print(a) print(a)
with open(r'C:\users\CM\Desktop\test.txt','r',encoding='utf-8') as file1:
file1.write(new_data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment