In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the python file how to read and write the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this python file how to read and write the article will have a harvest, let's take a look.
1. Read, the read () method returns the string saved in the file.
The readlines () method, which gets a list of strings from the file. Each string in the list is each line in the text.
> helloContent = file.read () > helloContent'Hello worldview'
2. Write, pass w as the second parameter to open (), open the file in writing mode, and you can write the content to the file by write ().
W mode deletes the original contents of the file and rewrites it.
If you do not want to delete the original content, you can add the content to the file in a mode.
> baconFile = open ('bacon.txt', 'w') > baconFile.write (' Hello world!\ n') 13 > > baconFile.close () > baconFile = open ('bacon.txt',' a') > baconFile.write ('Bacon is not a vegetable.') 25 > baconFile.close () > baconFile = open (' bacon.txt') > content = baconFile.read () > > baconFile.close () > > print (content) Hello worldstanding Bacon is not a vegetable. This is the end of the article on "how to read and write python files". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to read and write python files". If you want to learn more, you are 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.