Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

bellcode / lesson12-4

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • lesson12-4
  • diy.py
Find file
BlameHistoryPermalink
  • BellCodeEditor's avatar
    save project · 35002ff5
    BellCodeEditor committed 4 years ago
    35002ff5
diy.py 724 Bytes
Edit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9'
url=r'c:\Users\ryc66\OneDrive - 6699e5\Desktop\1.txt'
# file=open(url,"w",encoding="utf-8")
# file.write('小兰:12本\n')
# file.write('小丽:11本\n')
# file.write('李文:9本')
# file.close()
# file=open(url,"a",encoding="utf-8")
# file.write('小明:10本\n')
# file.close()
# with open(url,"a",encoding="utf-8") as file:
#     file.write('小红:13本\n')
new=""
with open(url,"w+",encoding="utf-8") as file:
    for i in file:
        if '李文:9本' in i:
            i=i.replace('李文:9本','李文:10本')
        new+=i
# print(new)        
# with open(url,"w",encoding="utf-8") as file:
    file.write(new)