Working with files in Python
Introduction
In this article you will learn how to organize file handling in Python 3.
Create a file
files.py
and copy the code from the examples into it.
You can run the file with the command
python3 files.py
| Create |
| open(): Open |
| close(): Close |
| with: Context manager |
| read(): reading a file |
| readline(): line-by-line reading |
| Clear the file |
| Copy the file |
| Write to a file |
| Append to the file |
| glob basics |
| Search by pattern |
| Search in multiple directories |
| Search in subdirectories |
| Search for hidden files |
| Copy options |
| copyfile |
| copy |
| move |
| cwd() |
| stat(): Metadata |
| exists(): Check existence |
Article author: Andrei Olegovich