Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Last active November 6, 2023 11:40
Show Gist options
  • Save vhbui02/33b7cdef9b1efec8a2e1e215b4791855 to your computer and use it in GitHub Desktop.
Save vhbui02/33b7cdef9b1efec8a2e1e215b4791855 to your computer and use it in GitHub Desktop.
[os module] some method I will use and try to remember

os module

os.chdir() # Change current working dir os.environ # Return an object, value = List of all env vars os.environ.get() # Access env var + def value + no exception (return None) os.environ[] # Access env var + no def + yes exception (KeyError) os.getcwd() # Get current working dir os.getenv() # Access env var + def value + no exception (return None) os.listdir() # Returns a List contains files and subdirectories os.mkdir() # Add new folder os.path # Return an object that can do path manipulation os.scandir() # Returns an iterator of os.DirEntry objs, which are entries in the given directory os.scandir(), is_file() # Returns True if it's a file os.path.isfile(path) # Returns True if path is a file or a symlink os.path.exists(path) # Returns True if path is a file, a directory or a symlink

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment