Call function with named parameters from dictionary

Viewed 50

Let's say I have such function:

def fun(n, m, verbose=0, use_fib_heap=False):
    '''blah blah'''
    pass

Then I parse command line args and try to run it as specified:

from sys import argv
opts = dict()
for arg in argv[1:]:
    if arg.startswith('--'):
        if '=' in arg:
            p, v = arg[2:].split('=')[:2]
            opts[p] = v
        else:
            p = arg[2:]
            opts[p] = True

How can I call fun, if I run my code as python3 code.py --verbose=3 --use_fib_heap?

1 Answers
Related