当前位置:网站首页>4. File modification
4. File modification
2022-07-06 02:43:00 【wwanxinghao】
General methods for modifying the contents of documents :
Rewrite the data into a new file , Then delete the old file , Then change the copy to the main version
The following is a general's surname “ Zhou ” Replace with last name :“ Yang ” The operation of
The code is as follows :
import os
with open(' name .txt',mode='r',encoding='utf-8') as f1,\
open(' name - copy .txt',mode='w',encoding='utf-8') as f2:
for i in f1:
if i.startswith(' Zhou '):
i = i.replace(' Zhou ',' Yang ')
f2.write(i)
os.remove(' name .txt') # Delete the original document
os.rename(' name - copy .txt',' name .txt') # Rename the copy file
边栏推荐
- Thinking on Architecture Design (under continuous updating)
- How does yyds dry inventory deal with repeated messages in the consumption process?
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
- Sword finger offer 29 Print matrix clockwise
- Y a - t - il des cas où sqlcdc surveille plusieurs tables et les associe à une autre? Tout fonctionne dans MySQL
- Reset nodejs of the system
- Is there a case where sqlcdc monitors multiple tables and then associates them to sink to another table? All operations in MySQL
- Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
- 一个复制也能玩出花来
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
力扣今日題-729. 我的日程安排錶 I
微服务注册与发现
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
Building the prototype of library functions -- refer to the manual of wildfire
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
Introduction to robotframework (II) app startup of appui automation
Communication between microservices
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
不赚钱的科大讯飞,投资价值该怎么看?
2.13 simulation summary
DDoS attacks - are we really at war?
数据准备工作
Spherical lens and cylindrical lens
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
Y a - t - il des cas où sqlcdc surveille plusieurs tables et les associe à une autre? Tout fonctionne dans MySQL
Master data management theory and Practice
[postgraduate entrance examination English] prepare for 2023, learn list5 words
How does yyds dry inventory deal with repeated messages in the consumption process?
Universal crud interface
Shell script updates stored procedure to database
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
剑指 Offer 29. 顺时针打印矩阵
HDU_ p1237_ Simple calculator_ stack
Sword finger offer 29 Print matrix clockwise
Maturity of master data management (MDM)
Pure QT version of Chinese chess: realize two-man, man-machine and network games