parsing function parameters

Lee Harr missive at hotmail.com
Wed Aug 3 14:33:21 EDT 2011


Needed to make one change... for functions with no default args:


def pdict(f):
    parameter_defaults = {}
    defaults = f.func_defaults
    if defaults is not None:
        defaultcount = len(defaults)
    else:
        defaultcount = 0
    argcount = f.func_code.co_argcount
    for i in xrange(f.func_code.co_argcount):
        name = f.func_code.co_varnames[i]
        value = None
        if i >= argcount - defaultcount:
            value = defaults[i - (argcount - defaultcount)]
        parameter_defaults[name] = value
    return parameter_defaults

 		 	   		  



More information about the Python-list mailing list