0

My project is structured like that:

module/
  module.py
  /utils
    utils.py 

In utils.py I import modules like NumPy, and when I import utils using from utils import utils (which I don't get why it wouldn't be just import utils and I'll be glad if someone could explain) I can access the NumPy module from utils with utils.numpy, is there a way to prevent exposing my imports from submodules/sub-packages?

Tomergt45
  • 579
  • 1
  • 7
  • 19
  • These threads: https://stackoverflow.com/questions/24302754/python-submodule-imports-using-init-py ; https://stackoverflow.com/questions/12229580/python-importing-a-sub-package-or-sub-module for your sub-question. This thread: https://stackoverflow.com/questions/36015605/prevent-python-packages-from-re-exporting-imported-names for your main question. – mabergerx Aug 03 '20 at 12:59
  • The last linked discussion doesn't mention [Python's new module-level `__getattr__` and `__dir__` functions](https://docs.python.org/3.7/reference/datamodel.html#customizing-module-attribute-access), and you have to dig for any mention of [`__all__`](https://docs.python.org/3.8/reference/simple_stmts.html#index-38). – Matthew Willcockson Aug 04 '20 at 13:39

0 Answers0