I have a simple module like this:
CMD_MAP = {
"action": handler
}
def handler(x):
print(x)
if __name__ == "__main__":
CMD_MAP["action"]("hello")
When trying to run/import it, it throws a
File ".../example.py", line 2, in <module>
"action": handler
NameError: name 'handler' is not defined
However, when I change the CMD_MAP to :
CMD_MAP = {
"action": lambda x: handler(x)
}
it works without issues. Can someone explain why?
handlerbeforeCMD_MAP, it will not work as expected because the "action" key would holdNone(thehandlerfunction has noreturn)