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


Groups > comp.lang.python > #10819

RE: parsing function parameters

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <missive@hotmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'args': 0.05; 'defaults': 0.07; 'positional': 0.09; 'subject:parameters': 0.09; 'subject:parsing': 0.09; 'subject:function': 0.16; 'suggestions!': 0.16; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.16; 'def': 0.16; 'header:In-Reply-To:1': 0.22; 'trying': 0.23; 'parameters.': 0.23; 'keyword': 0.25; 'string': 0.26; 'function': 0.26; '(and': 0.27; 'forgot': 0.29; 'match': 0.30; 'thanks': 0.31; 'it.': 0.33; 'to:addr:python-list': 0.34; 'calling': 0.34; '\xa0\xa0\xa0': 0.34; 'none': 0.35; 'some': 0.37; 'but': 0.37; 'could': 0.37; 'subject:: ': 0.38; 'think': 0.38; 'to:addr:python.org': 0.39; 'saw': 0.64; 'received:65.55.90.24': 0.84; 'received:snt0-omc1-s13.snt0.hotmail.com': 0.84
X-Originating-IP [70.101.97.52]
From Lee Harr <missive@hotmail.com>
To <python-list@python.org>
Subject RE: parsing function parameters
Date Wed, 3 Aug 2011 22:30:03 +0430
Importance Normal
In-Reply-To <1312388985.25995.11.camel@tim-laptop>
References <1312388985.25995.11.camel@tim-laptop>
Content-Type text/plain; charset="windows-1256"
Content-Transfer-Encoding 8bit
MIME-Version 1.0
X-OriginalArrivalTime 03 Aug 2011 18:00:04.0574 (UTC) FILETIME=[2C247FE0:01CC5207]
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1857.1312394477.1164.python-list@python.org> (permalink)
Lines 61
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312394477 news.xs4all.nl 23946 [2001:888:2000:d::a6]:50182
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10819

Show key headers only | View raw


>> I am trying to get some information about a function
>> before (and without) calling it.


> how about


def pdict(f):

    parameter_defaults = {}

    defaults = f.func_defaults

    defaultcount = len(defaults)

    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




> No need for the string parameters.
>
> Tim




That's it!



I saw the func_defaults, but could not see how to

make them match up with the co_varnames. I forgot

that keyword args must follow the positional args (duh).



I think this is going to work perfectly.


Thanks to all for the suggestions!


 		 	   		  

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


Thread

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

csiph-web