Get the App
SLTechnology News&Howtos  ›  Development  › 

What does python do with files?

Shulou Source: shulou.com Published: 2022-05-31 17:45:57 09月21日 Update

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.

Tags: File knowledge program article language processing content handle object method characteristic run different powerful large free binary code name most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia Shulou Information Shulou Tech Info Xiaomi