当前位置:网站首页>2. File operation - write
2. File operation - write
2022-07-06 08:17:00 【wwanxinghao】
1、 Pattern mode=w
# Pattern mode=w Write data to file , If the file does not exist, create a new file , If the file exists , Then empty the file and write again
f = open(' New files .txt',mode='w',encoding='utf-8')
f.write(' the weather is nice today ')
2、 Write the data in the list to the text
Be careful :1. normal open Outside the loop ,
2. The list is connected after being written to the file , It needs to be separated by carriage return
# A list is written to the file
l = ['python','java','go']
f = open(' New files .txt',mode='w',encoding='utf-8')
for i in l:
f.write(i)
f.write('\n')
3. Append write (append):a
l = ['python','java','go']
f = open(' New files .txt',mode='a',encoding='utf-8')
for i in l:
f.write(i)
4. File opening and playing need to be closed :f.close(), Not closing , When the file is large, it will consume server resources , File operation occupied , You need to wait until the program finishes running before releasing resources
边栏推荐
- Tidb backup and recovery introduction
- ESP系列引脚說明圖匯總
- C language custom type: struct
- Migrate data from SQL files to tidb
- Secure captcha (unsafe verification code) of DVWA range
- Wireshark grabs packets to understand its word TCP segment
- 使用 TiUP 升级 TiDB
- Pyqt5 development tips - obtain Manhattan distance between coordinates
- Hcip day 16
- Database basic commands
猜你喜欢
Interview Reply of Zhuhai Jinshan
21. Delete data
【T31ZL智能视频应用处理器资料】
Go learning notes (3) basic types and statements (2)
Leetcode question brushing record | 203_ Remove linked list elements
Machine learning - decision tree
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
. Net 6 learning notes: what is NET Core
NFT smart contract release, blind box, public offering technology practice -- contract
Hcip day 16
随机推荐
Introduction to backup and recovery Cr
Golang DNS write casually
Parameter self-tuning of relay feedback PID controller
华为云OBS文件上传下载工具类
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
[t31zl intelligent video application processor data]
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached
【云原生】手把手教你搭建ferry开源工单系统
ESP系列引脚說明圖匯總
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
Asia Pacific Financial Media | designer universe | Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers
ROS learning (IX): referencing custom message types in header files
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
Secure captcha (unsafe verification code) of DVWA range
IP lab, the first weekly recheck
Nacos Development Manual
Data governance: Data Governance under microservice architecture
数据治理:微服务架构下的数据治理
Résumé des diagrammes de description des broches de la série ESP
C语言自定义类型:结构体