当前位置:网站首页>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
边栏推荐
- 1. Color inversion, logarithmic transformation, gamma transformation source code - miniopencv from zero
- [Yugong series] creation of 009 unity object of U3D full stack class in February 2022
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Machine learning - decision tree
- [research materials] 2021 Research Report on China's smart medical industry - Download attached
- Introduction to backup and recovery Cr
- 2.10transfrom attribute
- On why we should program for all
- 让学指针变得更简单(三)
- flask返回文件下载
猜你喜欢

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

21. Delete data

【T31ZL智能视频应用处理器资料】

Easy to use tcp-udp_ Debug tool download and use

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center

将 NFT 设置为 ENS 个人资料头像的分步指南

Chinese Remainder Theorem (Sun Tzu theorem) principle and template code

Uibehavior, a comprehensive exploration of ugui source code

Learn Arduino with examples
![[research materials] 2021 live broadcast annual data report of e-commerce - Download attached](/img/a6/74da2f44c7b6b22fed2f8e41a55988.jpg)
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached
随机推荐
Data governance: misunderstanding sorting
Common functions for PHP to process strings
Parameter self-tuning of relay feedback PID controller
使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
1202 character lookup
华为云OBS文件上传下载工具类
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Tidb backup and recovery introduction
vulnhub hackme: 1
Image fusion -- challenges, opportunities and Countermeasures
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
From monomer structure to microservice architecture, introduction to microservices
使用 BR 恢复 S3 兼容存储上的备份数据
C语言自定义类型:结构体
Wincc7.5 download and installation tutorial (win10 system)
2.10transfrom attribute
从 TiDB 集群迁移数据至另一 TiDB 集群
Onie supports pice hard disk
It's hard to find a job when the industry is in recession
Use Alibaba icon in uniapp