본문 바로가기
Python(Eng. ver)

23. Python File I/O Library

by 곽정우 2024. 3. 21.

1. OS

The os module in Python provides many functions and utilities for interacting with the operating system. This module allows userto perform operations on files, directories, or the operating system itself.

 

2. glob

The glob module provides functions and utilities for interacting with the operating system. This module allows user to perform operations on files, directories, or the operating system itself.

Key features :

  • Matching file name patterns using wildcard characters
  • Searching for multiple file listings
  • Finding files that meet specific conditions

 

3. fileinput

The fileinput module in Python is useful for iterating over multiple input streams simultaneously. The main use of this module is to write scripts that read multiple files specified on the command line simultaneously.

Key features:

  • Iterating over multiple files at once
  • Reading the contents of each file line by line
  • Processing and modifying file contents

 

3-1. Finding and changing the first line of each file

 

3-2. Changing the found lines

 

3-3. Finding keywords and replacing them with desired text

 

4. pickle

The pickle module provides a process for serializing and deserializing Python object structures. In other words, it allows user to convert Python objects (lists, dictionaries, class instances, etc.) into byte streams and vice versa.

Key features:

  • Object serialization and deserialization
  • Saving and loading objects from files
  • Object transmission over networks

 

5. Shutil

The shutil module is a utility module in Python for performing high-level file operations. It extends the basic functionality provided by the os module.

Key features:

  • Copying files and directories
  • Moving files and directories
  • Deleting files and directories
  • Copying directory trees  

 

6. fnmatch

The fnmatch module is used to match file names to patterns. This module compares file names with wildcard patterns to determine if they match.

Key features:

  • Wildcard pattern matching: Checking if file names match using wildcard patterns such as * ? []
  • Searching for a list of file names: Searching for a list of file names that match specific patterns
  • Filtering file names: Extracting only file names that meet specific conditions

 

7. Data Compression

Python provides several modules for data compression and archive creation. These modules allow user to process data in various compression and archive formats.

 

7-1 zlib

'Python(Eng. ver)' 카테고리의 다른 글

24. Directory Management Program  (0) 2024.03.22
22. Variable type annotation  (0) 2024.03.21
21. Creating a vocabulary book using file input and output  (0) 2024.03.21
20. File I/O in Python  (0) 2024.03.20
19. Python Module  (0) 2024.03.20