From e9308339aee2b9313e649bd462db8873a4fddc4a Mon Sep 17 00:00:00 2001 From: SabareesanThirukumaran Date: Sun, 22 Jan 2023 18:26:24 +0000 Subject: [PATCH 1/2] Adding os changes to python cheatsheet --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 8fde845..d907753 100644 --- a/README.md +++ b/README.md @@ -1100,6 +1100,44 @@ import re '\w' == '[a-zA-Z0-9_]' # Alphanumeric ``` +### OS +**OS is a Python package which allows users to control their device as well as their files from the comfortable space of their environment** +```python +import os + +#DIRECTORIES +os.getcwd() # Gets the current directory +os.mkdir() # Creates a new directory +os.chdir() # Change the directory +os.getcwd() # Change directory to the drive +os.rmdir() # Remove a directory +os.listdir() # Lists all directories in the specified directory + +# PLATFORM +os.name # Recieve the current platform you are on + +# ENVIRONMENT +os.environ # Recieve all of the environment variables of your device +os.getenv() # Output your current environment +os.system("cls") # Clears the current terminal +os.system("clear") # Clears the current terminal + +# FILE +os.rename(src, dst) # Rename a file +os.startfile(dst) # Open a file +os.walk(dst) # Outputs the entire path to your current route directory +os.remove(dst) # Removes a file + +# PATH +os.path() # Outputs your current path +os.path.basename() # Returns just the filename of the current path +os.path.dirname() # Returns the directory until your current path +os.path.exists() # Checks if a path exists or not +os.path.isdir() # Checks if a directory exists +os.path.isfile() # Checks if a file exists +os.path.join() # Joins two different paths together +os.path.split() # Splits the entire path into different sections for readability +``` Credits ------ From 862db7e290533e8da503f18f99ad7de778f0abb5 Mon Sep 17 00:00:00 2001 From: SabareesanThirukumaran Date: Sun, 22 Jan 2023 19:01:19 +0000 Subject: [PATCH 2/2] Additional OS import to python cheatsheet --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d907753..a7fa495 100644 --- a/README.md +++ b/README.md @@ -1136,7 +1136,7 @@ os.path.exists() # Checks if a path exists or not os.path.isdir() # Checks if a directory exists os.path.isfile() # Checks if a file exists os.path.join() # Joins two different paths together -os.path.split() # Splits the entire path into different sections for readability +os.path.split() # Splits the entire path into different sections for easy readability ``` Credits