Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10821

RE: parsing function parameters

From Lee Harr <missive@hotmail.com>
Subject RE: parsing function parameters
Date 2011-08-03 23:03 +0430
Newsgroups comp.lang.python
Message-ID <mailman.1859.1312396471.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

 		 	   		  

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: parsing function parameters Lee Harr <missive@hotmail.com> - 2011-08-03 23:03 +0430

csiph-web