I have a need for functions with default arguments that have to be set at function runtime (such as empty lists, values derived from other arguments or data taken from the d
You could do something like this:
def getArg(): try: return arg except NameError: return 0 def foo(x, y=getArg): y = y() print(y) foo(1) # Prints 0 (Default) arg = 7 # Set by argparse? foo(2) # Prints 7 (Dynamic global) foo(3, lambda:9) # Prints 9 (Dynamic passed)