For a wrapper function, why wouldn't the following approach work:
# 3. DISALLOW EXECUTION IN MAIN
def disallow_main(func):
if __name__ == '__main__':
raise RuntimeError("Cannot run from main.")
return func
@disallow_main
def echo(prompt='-> '):
_inp = input(prompt)
print ("ECHO: %s" % _inp)
That is, why does it raise before defining the function? How should the wrap be constructed properly?