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

What does python do with files?

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you the relevant knowledge about how to deal with documents in python. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

The operating environment of this tutorial: windows7 system, Python 3.9.1 Dell G3 computer.

1. Reading and writing of documents

Open () is used to read or write a file and returns a file handle, which provides a way to read or write file data.

With open ('data.txt', 'w') as f: data =' some data to be written to the file'f.write (data)

2. Get the list of files

The file name has a matching pattern. Suppose we want to find all the .txt files in the directory, which can be done using glob (). The glob () method creates a generator that allows us to iterate.

> txt_files = list (Path ('.'). Glob ("* .txt") Print ("Txt files:", txt_files)... Txt files: [PosixPath ('hello_world.txt'), PosixPath (' hello.txt')] what are the five characteristics of python? the five characteristics of python: 1. It's easy to learn, and when you develop a program, you focus on solving problems, not understanding the language itself. two。 Object-oriented, compared with other major languages such as C++ and Java, Python implements object-oriented programming in a very powerful and simple way. 3. Portability, Python programs can run on a variety of platforms without modification. 4. Explanation, programs written in Python do not need to be compiled into binary code and can be run directly from the source code. 5. Open source, Python is one of FLOSS (Free / Open Source Software).

These are all the contents of the article "how to deal with documents in python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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