I am trying to understand how to structure python projects but am encountering some problems.
using __init__.py
for bundling imports
The way I understood it is that a packages __init__.py
is run once I import said package (here customQtWidgets
)
from scriptcommander.util import TOKENS
from scriptcommander.widgets import customQtWidgets
# defining
SCRIPTS = {
"material set opaque" : {
TOKENS.FUNCTION_LABEL: "material set opaque",
TOKENS.FUNCTION: setMaterialOpaque,
TOKENS.FUNCTION_ARGS: [
comboBox.ComboboxConfig(itemList=OBJECT_SELECTION),
checkBox.CheckboxConfig(label="set opaque", checked=True)
]
}
}
customQtWidgets's __init__.py
looks like this.
from scriptcommander.widgets.customQtWidgets import checkBox, comboBox, boxSlider
As this list of imports might grow over the course of the project, I want to define them centrally using init.py.
However, if I run my project I get:
comboBox.ComboboxConfig(itemList=OBJECT_SELECTION),
NameError: name 'comboBox' is not defined
If I replace the import in init.py with a simple print, it get's run.