diff --git a/p.py b/p.py new file mode 100644 index 0000000..7cee2ad --- /dev/null +++ b/p.py @@ -0,0 +1,16 @@ +new_data='' +file1=open(r"C:\Users\HP\Desktop\book.txt",'r',encoding='utf-8') +for data in file1: + if '小强:10本' in data: + data=data.replace('小强:10本','小强:11本') + if '小兰:12本' in data: + data=data.replace('小兰:12本','小兰:14本') + new_data+=data +file1.close() +file1=open(r"C:\Users\HP\Desktop\book.txt",'w',encoding='utf-8') +file1.write(new_data) +file1.close() +file1=open(r"C:\Users\HP\Desktop\book.txt",'r',encoding='utf-8') +a=file1.read() +print(a) +file1.close()