Commit 7e5bb8ae by BellCodeEditor

save project

parent 6b18b463
Showing with 10 additions and 6 deletions
new_data = ''
with open(r'C:\Users\Huawei\Desktop\book.txt','r',encoding='utf-8') as file:
for date in file:
if '小强:10本' in date:
print('文件中有此数据。')
if '小兰:12本' in date:
print('文件中有此数据。')
\ No newline at end of file
for data in file:
if '小强:10本' in data:
data = data.replace('10','11')
new_data += data
else:
new_data += data
with open(r'C:\Users\Huawei\Desktop\book.txt','w',encoding='utf-8') as file:
file.write(new_data)
\ No newline at end of file
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