当前位置:网站首页>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
边栏推荐
- Entity class design for calculating age based on birthday
- [research materials] 2022 China yuancosmos white paper - Download attached
- Huawei cloud OBS file upload and download tool class
- Golang DNS write casually
- Vocabulary notes for postgraduate entrance examination (3)
- 24. Query table data (basic)
- Data governance: Data Governance under microservice architecture
- 21. Delete data
- Mex related learning
- 将 NFT 设置为 ENS 个人资料头像的分步指南
猜你喜欢
Sanzi chess (C language)
Make learning pointer easier (3)
Pangolin Library: control panel, control components, shortcut key settings
File upload of DVWA range
Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
24. Query table data (basic)
22. Empty the table
ESP系列引脚说明图汇总
21. Delete data
Wincc7.5 download and installation tutorial (win10 system)
随机推荐
Upgrade tidb with tiup
Data governance: 3 characteristics, 4 transcendence and 3 28 principles of master data
从 TiDB 集群迁移数据至另一 TiDB 集群
24. Query table data (basic)
Pangolin Library: control panel, control components, shortcut key settings
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
"Friendship and righteousness" of the center for national economy and information technology: China's friendship wine - the "unparalleled loyalty and righteousness" of the solidarity group released th
1204 character deletion operation (2)
21. Delete data
从 SQL 文件迁移数据到 TiDB
649. Dota2 Senate
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
将 NFT 设置为 ENS 个人资料头像的分步指南
A Closer Look at How Fine-tuning Changes BERT
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
Day29-t77 & t1726-2022-02-13-don't answer by yourself
Vocabulary notes for postgraduate entrance examination (3)
Data governance: misunderstanding sorting
"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa