I have a module in which I import other modules (typically sys or os), and when I import the module with
import mymodule
if I do something like this
dir(mymodule)
I get not only the submodules of the module, but also os et al.
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'os', 'sys', 'submodule']
Is there a way to avoid to have the modules imported inside my module to show up in the symbol table of the module? Is it possible to keep it private?
Well, you can delete the module from the namespace using del:
import os
# ... all other code here
del os
After that it won't be visible anymore when importing.
However, this won't work when the modules are actually used...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With