The operating system module

The operating system(os) module is the best mechanism to access the different functions in our operating system. The use of this module will depend on the operating system that is used. If we use this module, we will have to adapt the script if we go from one operating system to another.

This module allows us to interact with the OS environment, filesystem, and permissions. In this example, we check whether the name of a text file passed as a command-line argument exists as a file in the current execution path and the current user has read permissions to that file.

You can find the following code in the check_filename.py file in os module subfolder:

import sysimport osif len(sys.argv) == 2: filename = sys.argv[1] ...

Get Mastering Python for Networking and Security now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.