当前位置:网站首页>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
边栏推荐
- MySQL winter vacation self-study 2022 11 (5)
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
- 深度解析链动2+1模式,颠覆传统卖货思维?
- Bigder: I felt good about the 34/100 interview, but I didn't receive the admission
- Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
- 2.12 simulation
- [matlab] access of variables and files
- 米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
- C语言sizeof和strlen的区别
猜你喜欢
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
Keyword static
Black high-end responsive website dream weaving template (adaptive mobile terminal)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Pure QT version of Chinese chess: realize two-man, man-machine and network games
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
A copy can also produce flowers
Master data management theory and Practice
[untitled] a query SQL execution process in the database
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures
Structural theme model (I) STM package workflow
有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
2.11 simulation summary
构建库函数的雏形——参照野火的手册
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
微服务间通信
PMP每日一练 | 考试不迷路-7.5
Communication between microservices
UE4 - how to make a simple TPS role (I) - create a basic role
Elimination games
RobotFramework入门(二)appUI自动化之app启动
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
Pure QT version of Chinese chess: realize two-man, man-machine and network games
故障分析 | MySQL 耗尽主机内存一例分析
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
淘宝焦点图布局实战
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)