I try to make my code more modular for general readability. When moving functions and dictionaries storing function names to external py.files in the same folder, it raises a name error. It does however work fine when in one file and the dict-file importing the function file (please see below):
Does not work:
data.py
modes = {'add' : {'adds an entry': addMode}}
func.py
def addMode():
print('tada')
Main file
from data import modes
from func import addMode
for v, button in modes.items():
for tip, function in button.items():
function()
Does work but seems messy:
data2.py
from func import addMode
modes = {'add' : {'adds an entry': addMode}}
Main file
from data2 import modes
for v, button in modes.items():
for tip, function in button.items():
function()
Is there a reason why the former does not work? It seems that order is of importance for the addMode in the dict to not cause a NameError, is there a way to force it?