Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'argument': 0.05; 'string': 0.09; 'ex:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'python': 0.11; 'def': 0.12; '(also': 0.16; '54,': 0.16; 'function?': 0.16; 'googling': 0.16; 'help?': 0.16; 'inverse': 0.16; 'parser.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'mechanism': 0.19; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'pass': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; '2009': 0.29; 'returned': 0.30; 'work.': 0.31; "skip:' 10": 0.31; 'anybody': 0.35; 'convert': 0.35; 'test': 0.35; 'but': 0.35; 'google': 0.35; 'there': 0.35; 'i.e.': 0.36; 'possible': 0.36; 'hi,': 0.36; 'should': 0.36; 'searching': 0.37; 'problems': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'full': 0.61; 'email addr:gmail.com': 0.63; 'such': 0.63; 'talking': 0.65; 'difficulty': 0.68; 'online': 0.71; 'as:': 0.81; 'marzo': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: converting a string to a function parameter Date: Sun, 05 Jan 2014 14:58:09 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388951905 news.xs4all.nl 2905 [2001:888:2000:d::a6]:46618 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63217 On 1/5/14 2:39 PM, pietrodcof@gmail.com wrote: > Il giorno venerd́ 13 marzo 2009 08:52:39 UTC+1, koranthala ha scritto: >> Hi, >> Is it possible to convert a string to a function parameter? >> Ex: >> str = 'True, type=rect, sizes=[3, 4]' >> and I should be able to use it as: >> test(convert(str)) and the behaviour should be same as calling test >> with those values : >> i.e. test(True, type=rect, sizes=[3, 4]) >> >> I tried eval, but it did not work. And any other mechanism I think >> turns out to be creating a full fledged python parser. >> >> Is there any mechanism with which we can do this straight away? > > I need the exact opposite, what is the inverse function? > example: i pass to a function an argument > > m=[654,54,65] > def function(m): > return takethenameof(m) > > and it have to return to me 'm' not [654,54,65] or '[654,54,65]' > > anybody can help? > i think that when one is talking about a function he have to talk also of the inverse function (also because google have problems searching about this...) > The difficulty in writing such a function is that values don't have unique names, if they have names at all. What should be returned in these cases? m = [654, 54, 65] def function(m): m2 = m m3 = m[:] takethenameof(m) takethenameof(m2) takethenameof(m3) takethenameof(m[:]) takethenameof(2) takethenameof(2+2) There are samples online that try to do a "reasonable" job of this, but my googling isn't turning them up... -- Ned Batchelder, http://nedbatchelder.com