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


Groups > comp.lang.python > #63217

Re: converting a string to a function parameter

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 <python-python-list@m.gmane.org>
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 <ned@nedbatchelder.com>
Subject Re: converting a string to a function parameter
Date Sun, 05 Jan 2014 14:58:09 -0500
References <aaf29677-db0b-4749-84b1-ce965e0f545e@v5g2000prm.googlegroups.com> <ef4ee1e8-e247-4fda-ae5f-439dd9742a75@googlegroups.com>
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 <ef4ee1e8-e247-4fda-ae5f-439dd9742a75@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4963.1388951905.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

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


Thread

Re: converting a string to a function parameter pietrodcof@gmail.com - 2014-01-05 11:39 -0800
  Re: converting a string to a function parameter Ned Batchelder <ned@nedbatchelder.com> - 2014-01-05 14:58 -0500
  Re: converting a string to a function parameter Gary Herron <gary.herron@islandtraining.com> - 2014-01-05 12:09 -0800

csiph-web