There's something that I'm not grasping about python imports. I've read dozens of articles but I'm not finding a satisfactory answer. The situation is this:
I'm writing a package made of several modules. Let's say that the package is named pack1
. In the __init__.py
file, in order to expose the classes and functions I defined in my modules, I wrote:
from .module1 import *
from .module2 import *
...
Now, in module 1:
from math import sqrt # a tool that I need
class class1:
<body>
class class2:
<body>
....
class class100:
<body>
My problem is that when I
import pack1
in another project, I see sqrt
in pack1
's namespace. Do I have to import each one of the 100 classes separately in the __init__.py
file in order to avoid this and keep my namespace clean? Do I have to do some hack with the inspect module in __init__.py
in order to identify the classes that were defined and not imported (I think this would be very ugly)? Or, as I suspect, I'm mistaking something about how I should handle the module structure or the import statements?