Python Tutorial: os module for beginners

preview_player
Показать описание
In this video, I will cover the os module in python.

The os module in Python provides a way to interact with the operating system.
It allows you to handle environment variables, perform file operations, and more.

import os

Get the current working directory:
print("Current working directory:", current_directory)

List the contents of a directory:

Create a new directory:
print('Created directory: new_directory')

Delete a file:

Join paths:
print('Joined path:', file_path)

Check if a path exists, or if it’s a file or directory:

Execute a shell command:

Identify the OS type:

View all environment variables:
print(f'{key}: {value}')

Set an environment variable:

Get the value of an environment variable:
print('MY_VARIABLE:', test_var)

Delete an environment variable:
print('TEST_VARIABLE deleted.')
else:
print('TEST_VARIABLE does not exist.')

#python #pythonforbeginners #programming
Рекомендации по теме
welcome to shbcf.ru