From b3a5374a2787ee044623fabf01dad4316ebaf6f1 Mon Sep 17 00:00:00 2001 From: parasite Date: Tue, 18 Nov 2025 00:31:25 +0530 Subject: [PATCH 1/3] python os module commit --- os_py/os_module.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 os_py/os_module.py diff --git a/os_py/os_module.py b/os_py/os_module.py new file mode 100644 index 000000000000..48d6edb82679 --- /dev/null +++ b/os_py/os_module.py @@ -0,0 +1,89 @@ +import os + +# ------------------------------- +# šŸ“‚ 1. DIRECTORY OPERATIONS +# ------------------------------- +# print("Current Working Directory:", os.getcwd()) + +# # Create a new folder +# os.mkdir("demo_folder") +# print("\nAfter creating 'demo_folder':", os.listdir()) + +# # Rename folder +# os.rename("demo_folder", "renamed_folder") +# print("After renaming:", os.listdir()) + +# # Change directory +# os.chdir("renamed_folder") +# print("Now inside directory:", os.getcwd()) + +# # Go back to parent directory +# os.chdir("..") + +# # Remove directory +# os.rmdir("renamed_folder") +# print("After removing folder:", os.listdir()) + +# ------------------------------- +# 🧭 2. PATH HANDLING +# ------------------------------- +# print("\n--- Path Operations ---") +# path = os.getcwd() + +# print("Absolute Path:", os.path.abspath(path)) +# print("Is Directory:", os.path.isdir(path)) +# print("Is File:", os.path.isfile(__file__)) +# print("File Name:", os.path.basename(__file__)) +# print("Directory Name:", os.path.dirname(__file__)) +# print("Path Exists:", os.path.exists(path)) +# print("Joined Path:", os.path.join(path, "sample.txt")) + +# ------------------------------- +# šŸŒ 3. ENVIRONMENT VARIABLES +# ------------------------------- +# print("\n--- Environment Variables ---") +# print("OS Name:", os.name) +# print("Home Directory:", os.getenv("HOME") or os.getenv("USERPROFILE")) +# print("Python Path:", os.getenv("PATH").split(";")[0]) # Show first path + +# # Setting and unsetting an environment variable +# os.putenv("MY_VAR", "User_name") +# print("MY_VAR (after putenv):", os.getenv("MY_VAR")) + +# os.unsetenv("MY_VAR") +# print("MY_VAR (after unsetenv):", os.getenv("MY_VAR")) + +# ------------------------------- +# āš™ļø 4. SYSTEM COMMANDS +# ------------------------------- +print("\n--- System Commands ---") +# Example: list files using OS command +os.system("dir" if os.name == "nt" else "ls") + +# ------------------------------- +# 🧱 5. PROCESS INFORMATION +# ------------------------------- +print("\n--- Process Info ---") +print("Process ID:", os.getpid()) +print("CPU Count:", os.cpu_count()) + +# ------------------------------- +# šŸ” 6. FILE ACCESS & PERMISSIONS +# ------------------------------- +print("\n--- File Access & Permissions ---") +filename = "testfile.txt" +with open(filename, "a+") as f: + f.write("This is a test file for os module demo.\n") + +print("File Created:", filename) +print("File Size:", os.path.getsize(filename), "bytes") +print("Has Read Access:", os.access(filename, os.R_OK)) +print("Has Write Access:", os.access(filename, os.W_OK)) + +# ------------------------------- +# 🧩 7. CLEANUP +# ------------------------------- +os.remove(filename) +print("\nFile Removed:", filename) + +# print("\nāœ… All OS operations completed successfully!") From d476f6951234e0e888027fa6ed8503b51d6a5e50 Mon Sep 17 00:00:00 2001 From: parasite Date: Tue, 18 Nov 2025 13:22:53 +0530 Subject: [PATCH 2/3] python os module --- os_py/__init__.py | 0 os_py/os_module.py | 66 +++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 os_py/__init__.py diff --git a/os_py/__init__.py b/os_py/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/os_py/os_module.py b/os_py/os_module.py index 48d6edb82679..376955830c6f 100644 --- a/os_py/os_module.py +++ b/os_py/os_module.py @@ -3,55 +3,55 @@ # ------------------------------- # šŸ“‚ 1. DIRECTORY OPERATIONS # ------------------------------- -# print("Current Working Directory:", os.getcwd()) +print("Current Working Directory:", os.getcwd()) -# # Create a new folder -# os.mkdir("demo_folder") -# print("\nAfter creating 'demo_folder':", os.listdir()) +# Create a new folder +os.mkdir("demo_folder") +print("\nAfter creating 'demo_folder':", os.listdir()) -# # Rename folder -# os.rename("demo_folder", "renamed_folder") -# print("After renaming:", os.listdir()) +# Rename folder +os.rename("demo_folder", "renamed_folder") +print("After renaming:", os.listdir()) -# # Change directory -# os.chdir("renamed_folder") -# print("Now inside directory:", os.getcwd()) +# Change directory +os.chdir("renamed_folder") +print("Now inside directory:", os.getcwd()) -# # Go back to parent directory -# os.chdir("..") +# Go back to parent directory +os.chdir("..") -# # Remove directory -# os.rmdir("renamed_folder") -# print("After removing folder:", os.listdir()) +# Remove directory +os.rmdir("renamed_folder") +print("After removing folder:", os.listdir()) # ------------------------------- # 🧭 2. PATH HANDLING # ------------------------------- -# print("\n--- Path Operations ---") -# path = os.getcwd() +print("\n--- Path Operations ---") +path = os.getcwd() -# print("Absolute Path:", os.path.abspath(path)) -# print("Is Directory:", os.path.isdir(path)) -# print("Is File:", os.path.isfile(__file__)) -# print("File Name:", os.path.basename(__file__)) -# print("Directory Name:", os.path.dirname(__file__)) -# print("Path Exists:", os.path.exists(path)) -# print("Joined Path:", os.path.join(path, "sample.txt")) +print("Absolute Path:", os.path.abspath(path)) +print("Is Directory:", os.path.isdir(path)) +print("Is File:", os.path.isfile(__file__)) +print("File Name:", os.path.basename(__file__)) +print("Directory Name:", os.path.dirname(__file__)) +print("Path Exists:", os.path.exists(path)) +print("Joined Path:", os.path.join(path, "sample.txt")) # ------------------------------- # šŸŒ 3. ENVIRONMENT VARIABLES # ------------------------------- -# print("\n--- Environment Variables ---") -# print("OS Name:", os.name) -# print("Home Directory:", os.getenv("HOME") or os.getenv("USERPROFILE")) -# print("Python Path:", os.getenv("PATH").split(";")[0]) # Show first path +print("\n--- Environment Variables ---") +print("OS Name:", os.name) +print("Home Directory:", os.getenv("HOME") or os.getenv("USERPROFILE")) +print("Python Path:", os.getenv("PATH").split(";")[0]) # Show first path -# # Setting and unsetting an environment variable -# os.putenv("MY_VAR", "User_name") -# print("MY_VAR (after putenv):", os.getenv("MY_VAR")) +# Setting and unsetting an environment variable +os.putenv("MY_VAR", "User_name") +print("MY_VAR (after putenv):", os.getenv("MY_VAR")) -# os.unsetenv("MY_VAR") -# print("MY_VAR (after unsetenv):", os.getenv("MY_VAR")) +os.unsetenv("MY_VAR") +print("MY_VAR (after unsetenv):", os.getenv("MY_VAR")) # ------------------------------- # āš™ļø 4. SYSTEM COMMANDS From 2fdaac8291bb96825315f49c92db6ece75df6281 Mon Sep 17 00:00:00 2001 From: parasite Date: Tue, 18 Nov 2025 13:40:41 +0530 Subject: [PATCH 3/3] updated os module commit --- os_py/os_module.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/os_py/os_module.py b/os_py/os_module.py index 376955830c6f..562af12095d0 100644 --- a/os_py/os_module.py +++ b/os_py/os_module.py @@ -54,21 +54,14 @@ print("MY_VAR (after unsetenv):", os.getenv("MY_VAR")) # ------------------------------- -# āš™ļø 4. SYSTEM COMMANDS -# ------------------------------- -print("\n--- System Commands ---") -# Example: list files using OS command -os.system("dir" if os.name == "nt" else "ls") - -# ------------------------------- -# 🧱 5. PROCESS INFORMATION +# 🧱 4. PROCESS INFORMATION # ------------------------------- print("\n--- Process Info ---") print("Process ID:", os.getpid()) print("CPU Count:", os.cpu_count()) # ------------------------------- -# šŸ” 6. FILE ACCESS & PERMISSIONS +# šŸ” 5. FILE ACCESS & PERMISSIONS # ------------------------------- print("\n--- File Access & Permissions ---") filename = "testfile.txt" @@ -81,7 +74,7 @@ print("Has Write Access:", os.access(filename, os.W_OK)) # ------------------------------- -# 🧩 7. CLEANUP +# 🧩 6. CLEANUP # ------------------------------- os.remove(filename) print("\nFile Removed:", filename)