当前位置:网站首页>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
边栏推荐
- Qt发布exe软件及修改exe应用程序图标
- 【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
- Sword finger offer 30 Stack containing min function
- Patch NTP server at the beginning of DDoS counterattack
- 构建库函数的雏形——参照野火的手册
- Template_ Find the reverse pair of permutations_ Sort based on merge
- Pat 1046 shortest distance (20 points) simulation
- MySQL (IV) - transactions
- PMP每日一练 | 考试不迷路-7.5
- 如何精准识别主数据?
猜你喜欢
【若依(ruoyi)】启用迷你导航栏
Initial understanding of pointer variables
Advanced technology management - what is the physical, mental and mental strength of managers
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO
力扣今日題-729. 我的日程安排錶 I
Maturity of master data management (MDM)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
Introduction to robotframework (II) app startup of appui automation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
剑指 Offer 29. 顺时针打印矩阵
构建库函数的雏形——参照野火的手册
Shell脚本更新存储过程到数据库
主数据管理(MDM)的成熟度
How does yyds dry inventory deal with repeated messages in the consumption process?
Yyds dry inventory comparison of several database storage engines
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
Network Security Learning - Web vulnerabilities (Part 1)
Initial understanding of pointer variables
RobotFramework入门(三)WebUI自动化之百度搜索
Redis delete policy
【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
Bigder: I felt good about the 34/100 interview, but I didn't receive the admission
MySQL winter vacation self-study 2022 11 (6)
Shell script updates stored procedure to database
Pat grade a 1033 to fill or not to fill
Six stone management: why should leaders ignore product quality