Coding in Python 18 – The OS Module

In video number 18 of the Coding in Python series, we’ll check out the OS module, which will allow you to interact with your operating system.

YouTube player

Commands Used in this Video

Using the os module to print the current working directory

#!/usr/bin/env python3

import os

print(os.getcwd())

Renaming a file

#!/usr/bin/env python3

import os

print(os.getcwd())

os.rename("first.txt", "second.txt")

Running a system command

#!/usr/bin/env python3

import os

os.system('ls')

Using the os module with print statements

#!/usr/bin/env python3

import os

print("Your current working directory is: " +os.getcwd() + "\n\n")

print("The contents of this directory are:")
os.system('ls')

Brand-New Course!

Check out Jay’s new course on Ansible and start automating today!

Discount Vouchers


Receive 5% off an LPI exam voucher!

Exclusive Member Features

Support the channel and receive exclusive perks!