当前位置:网站首页>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
边栏推荐
- ESP系列引脚說明圖匯總
- flask返回文件下载
- Data governance: data quality
- Machine learning - decision tree
- hcip--mpls
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
- Flash return file download
- National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
- [untitled]
猜你喜欢
![[cloud native] teach you how to build ferry open source work order system](/img/fb/507f763791235bd00bc8201e5d7741.png)
[cloud native] teach you how to build ferry open source work order system
![[research materials] 2021 China online high growth white paper - Download attached](/img/51/bea6179e4fac88f8b550b4213a2bca.jpg)
[research materials] 2021 China online high growth white paper - Download attached
![[untitled]](/img/38/bc025310b9742b5bf0bd28c586ec0d.jpg)
[untitled]

Data governance: 3 characteristics, 4 transcendence and 3 28 principles of master data

23. Update data

The Vice Minister of the Ministry of industry and information technology of "APEC industry +" of the national economic and information technology center led a team to Sichuan to investigate the operat

Résumé des diagrammes de description des broches de la série ESP

Understanding of law of large numbers and central limit theorem

Wireshark grabs packets to understand its word TCP segment

Make learning pointer easier (3)
随机推荐
What are the ways to download network pictures with PHP
ROS learning (IX): referencing custom message types in header files
Uibehavior, a comprehensive exploration of ugui source code
Notes on software development
Pyqt5 development tips - obtain Manhattan distance between coordinates
Data governance: metadata management
Analysis of Top1 accuracy and top5 accuracy examples
Data governance: data quality
让学指针变得更简单(三)
08- [istio] istio gateway, virtual service and the relationship between them
从 TiDB 集群迁移数据至另一 TiDB 集群
Entity class design for calculating age based on birthday
649. Dota2 Senate
Binary tree creation & traversal
图像融合--挑战、机遇与对策
在 uniapp 中使用阿里图标
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
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
Wireshark grabs packets to understand its word TCP segment
使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据