Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write and close python files

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to write and close python files", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to write and close python files" this article.

1. Change mode to a to achieve continuous write append, but the append does not break the line, so you need to use the newline symbol before the added text.

2. File closing must be closed when it comes to data security.

Example

Stream = open (file='./666', mode='w', encoding='utf-8') print (stream) record ='18 April 17:00 FPX Competition RNG'stream.write (record) # File write stream.close () # File closure must be closed related to data security # if the open file does not exist Then a new file stream = open (file='./text1.txt', mode='w', encoding='utf-8') print (stream) # can be added continuously by changing mode to a, but the addition will not help us to change the line So when we need to wrap the text, we need to use the newline symbol stream = open (file='./text1.txt', mode='a', encoding='utf-8') print (stream) record ='\ nApril 18 17:00 FPX competition RNG'stream.write (record) # file to write stream.close () above is all the content of the article "how to write and close python files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report