Reputation: 55
I am playing around with import mechanism. Here's what happened:
dir/b.py -> Prints "hello"
dir/a.py --> Imports b.py
For the first time, when I imported b (from a.py), a directory named `_pycache_` popped up containing the bytecode version of b.py
Now, I have deleted b.py and tried to run a.py. I got the error saying that Python couldn't find a module named 'b', which makes sense. But why is the cached version still present (even after b.py is deleted)? I know the purpose of pycache, but I wonder if it doesn't add any memory overhead when there are, say, 20 files that are deleted but their cached versions continue to exist.
One more thing I have done is that I had explicitly added the __pycache__
directory to sys.path as follows:
Still, python is unable to do the import. Please help me understand the purpose of these cached files and please point out if I have misunderstood anything.
Upvotes: 0
Views: 30