Introduction to Python OS Module
In this tutorial, you will learn how to work along with Python’s os
module.
Table of Contents
- Introduction
- Basic Functions
- List Files / Folders in Current Working Directory
- Change working Directory
- Create Single and Nested Directory Structure
- Remove Single and Nested Directory Structure Recursively
- Example with Data Processing
- Conclusion
Introduction
Python is one of the most frequently used languages in recent times for various tasks such as data processing, data analysis, and website building. In this process, there are various tasks that are operating system dependent. Python allows the developer to use several OS-dependent functionalities with the Python module os
. This package abstracts the functionalities of the platform and provides the python functions to navigate, create, delete and modify files and folders. In this tutorial one can expect to learn how to import this package, its basic functionalities and a sample project in python which uses this library for a data merging task.
Some Basic Functions
Let’s explore the module with some example code.
Import the library:
import os
Let’s get the list of methods that we can use with this module.
print(dir(os))
Output:
['DirEntry', 'F_OK', 'MutableMapping', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT',