Lab 02: Custom Import System
Overview
Step 1: How Import Works
import sys
# sys.meta_path: list of finders checked in order
print("Meta path finders:")
for finder in sys.meta_path:
print(f" {type(finder).__name__}: {finder}")
# sys.path_hooks: factories for path-based finders
print("\nPath hooks:")
for hook in sys.path_hooks:
print(f" {hook}")
# sys.modules: already-imported modules cache
print(f"\nCached modules (count): {len(sys.modules)}")
print(f" 'os' cached: {'os' in sys.modules}")Step 2: MetaPathFinder — The Core Interface
Step 3: Custom Loader
Step 4: Import Hooks for Encrypted Modules
Step 5: Path Entry Finders
Step 6: pkgutil.iter_modules
pkgutil.iter_modulesStep 7: Module Reloading and Isolation
Step 8: Capstone — Plugin Loader System
Summary
Concept
API
Use Case
Last updated
