Simple quick question... say I have a self created package called miscfun
where some module/script in there looks like...
# helper.py
import re
import os
def foo(x):
# Do something with re
def bar(x):
# Do something with os
After setting up a proper setup.py etc.. I can then 'install' my package and load it using
import miscfun.helper
However, what I discovered just now is that I can also call
miscfun.helper.os
or
miscfun.helper.re
to 'use' the re
and os
modules! Isnt that weird and confusing? Can I somehow prevent this from happening?
(If this is not a normal situation, I'll gladly explain more, but for now I hope this suffices)
Well it's completely normal behaviour of python modules. Once you import
anything into your module, you introduce new key in module namespace (which is basically dict
as everything in python). And any key in module namespace can be accessed or imported elsewhere as usual.