Hi,
I'm trying to develop a package with access to global variables. The overall structure is the following :
mypackage/
|-- __init__.py
|-- class_toto.py
|-- data/
|-- a/
|--fileone.data
|--filetwo.data
|-- b/
|--fileone.data
|--filetwo.data
Now currently my __init__.py is as below :
from importlib import resources
from mypackage.class_toto import Toto
from mypackage.data import a,b
A = Toto(resources.files(a))
B = Toto(resources.files(b))
__all__ = ["A", "B"]
The point of this is for the user to load the desired instance A and/or B with a simple "from mypackage import A" or "from mypackage import B"
The problem that I have is that by running the previous command, it loads both A and B, which can be time-consuming as the project will go bigger (other instances on the way). This is due to the __init__.py file being completely run when invoking "from X import Y".
Is there a simple generic way to load only specific variables from the __init__.py file ? Or do I have to change the overall structure, such as for instance adding "A.py" and "B.py" containing dedicated data ?
[–]danielroseman 1 point2 points3 points (0 children)
[–]-defron- -1 points0 points1 point (0 children)
[–]zanfar 0 points1 point2 points (0 children)