Rapid Python #1

Devashish Patil
2 min readNov 11, 2023
Photo by Marc-Olivier Jodoin on Unsplash

Python os module

Python’s os module is often seen as a collection of basic file and directory manipulation tools, but it is a powerful gateway to the underlying operating system. It provides a plethora of features that can make one a better programmer. Check out this curated list

  • Environment Variable Manipulation: os.environ dictionary
  • Process Management: os.system() and os.popen()
  • File Locking and I/O Control: os.lockfile() , os.unlockfile(), os.lseek()
  • System Information Retrieval:
    For fetching system-level info such as current working directory, system name, user info
  • Platform-Specific Operations
    Example: os.urandom() generates random numbers using the system’s random number generator.
  • Path Manipulation and Expansion os.path.join() and os.path.expanduser()
  • File Permission ControlL os.chmod() and os.chown()

Other use cases:

  • Interfacing with System Services (like sending signals to processes)
  • Debugging and Exception Handling
  • Encoding and Decoding

History of Sets and Dictionary

Let’s understand a bit of history about Python Sets and Dictionaries

The set data structure in Python started off as a replica of the dict data structure, a key-value pair with dummy values.

Both use hashtables as the underlying data structure, which explains the average O(1) complexity for data lookup and insertion.

But since then the set’s and dict’s implementations have diverged from each other(e.g. arbitrary order in set vs insertion order in dict) and performance in various use cases differ.

If you like to see more such content, consider following.

--

--