def mk_getkw(kw, defaults,prefer_passed=False):
def getkw(*ls):<EOL><INDENT>r = [ kw[l] if test(kw,l) else defaults[l]<EOL>for l in ls ];<EOL>if len(r) == <NUM_LIT:1>: return r[<NUM_LIT:0>];<EOL>return r;<EOL><DEDENT>def getkw_prefer_passed(*ls):<EOL><INDENT>r = [ kw[l] if l in kw else defaults[l]<EOL>for l in ls ];<EOL>if len(r) == <NUM_LIT:1>: return r[<NUM_LIT:0>];<EOL>return r;<EOL><DEDENT>return getkw if not prefer_passed else getkw_prefer_passed<EOL>
a helper for generating a function for reading keywords in
interface functions with a dictionary with defaults

expects the defaults dictionary to have keywords you request.

example:
defaults = dict(a='a',b=3);
def bigfunc(**kw):
    getkw=mk_getkw(kw,defaults);

    # I want the callers' `a', or the default if s/he doesn't
    # supply it
    a=getkw('a');
    c = [a]*getkw('b');
    return c,c[0]; 

Option:
    prefer_passed -- use "l in kw" only, not test.