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


Groups > comp.lang.python > #10821 > unrolled thread

RE: parsing function parameters

Started byLee Harr <missive@hotmail.com>
First post2011-08-03 23:03 +0430
Last post2011-08-03 23:03 +0430
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#10821 — RE: parsing function parameters

FromLee Harr <missive@hotmail.com>
Date2011-08-03 23:03 +0430
SubjectRE: parsing function parameters
Message-ID<mailman.1859.1312396471.1164.python-list@python.org>
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

 		 	   		  

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web