Member-only story
5 Python Standard Libraries You’re Probably Underusing
Part 2: More built-in Python tools that improve reliability and developer productivity
Most Python developers install new libraries to solve problems that Python already solved.
The standard library is not just “basic utilities” - it contains carefully designed tools that can eliminate entire classes of bugs, improve readability, and make your code easier to reason about.
In this series, I have highlighted underused but high-leverage Python standard library features that quietly make your projects better.
Let’s dive in.
1. sourceFileLoader
use the built-in SourceFileLoader to import module name from non .py file.
example —
# my_module.py.txt
def greet():
return "Hello from non.py file!"# test.py
import importlib.util
from importlib.machinery import SourceFileLoader
# Load the module from the non-.py file
loader = SourceFileLoader(module_name, "my_module.py.txt")
spec = importlib.util.spec_from_loader("my_module", loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
print(module.greet())