Commit 853ea0db by BellCodeEditor

save project

parent 17e4b6a9
Showing with 16 additions and 8 deletions
newdata=""
with open(r"C:\Users\Administrator\Desktop\wuzi.txt","r",encoding="utf-8") as file: with open(r"C:\Users\Administrator\Desktop\wuzi.txt","r",encoding="utf-8") as file:
for data in file: for data in file:
if "小强:10本" in data: if "小强:10本" in data:
print("小强数据在文件中") data=data.replace("10","11")
if "小兰:12本" in data:
print("小兰数据在文件中") newdata += data
else:
print("数据不在文件中")
break with open(r"C:\Users\Administrator\Desktop\wuzi.txt","w",encoding="utf-8") as file:
\ No newline at end of file file.write(newdata)
with open(r"C:\Users\Administrator\Desktop\wuzi.txt","r",encoding="utf-8") as file:
a=file.read()
print(a)
\ 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