I know that the order of functions in a script doesn't matter. However, this sample code doesn't work:
main.py
_FUNCTIONS = (_foo, _bar)
def myfunc():
for f in _FUNCTIONS:
print(f())
def _foo():
return False
def _bar():
return True
myfunc()
provides the following error
File "main.py", line 1, in <module>
_FUNCTIONS = (_foo, _bar)
NameError: name '_foo' is not defined
However, if I don't use _FUNCTIONS
and inject (_foo, _bar)
into a code this will work:
def myfunc():
for f in (_foo, _bar):
print(f())
def _foo():
return False
def _bar():
return True
myfunc()
Why the first example doesn't work?
How can I extract the list of functions in a variable and put it on the top of the script?