diff --git a/diy1.py b/diy1.py index f406ecf..3c1bbfc 100644 --- a/diy1.py +++ b/diy1.py @@ -1,10 +1,5 @@ -new_data='' -with open(r"C:\Users\xxd\Desktop\j.txt",'r',encoding='utf-8') as file1: - - for data in file1: - if '小强:10本' in data: - data=data.replace('小强:10本','小强:11本') - new_data +=data - -with open(r"C:\Users\xxd\Desktop\book.txt","a",encoding='utf-8')as file1: - file1.write(new_data) \ No newline at end of file +with open(r"C:\Users\xxd\Desktop\j.txt",'r',encoding='utf-8') as fill: + a=[fill.read()] + for i in a: + if 'ads' in i: + print('在文件中') \ No newline at end of file