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


Groups > comp.lang.python > #63219

Re: converting a string to a function parameter

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gary.herron@islandtraining.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'argument': 0.05; 'string': 0.09; '*is*': 0.09; 'ex:': 0.09; 'namespace': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'subject:string': 0.09; 'python': 0.11; 'def': 0.12; '"a"': 0.16; '"b"': 0.16; '(also': 0.16; 'function?': 0.16; 'help?': 0.16; 'inverse': 0.16; 'parser.': 0.16; 'wrote:': 0.18; 'mechanism': 0.19; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'instance,': 0.24; 'received:emailsrvr.com': 0.24; 'received:(smtp server)': 0.26; 'pass': 0.26; 'code:': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'function': 0.29; '2009': 0.29; 'am,': 0.29; '(like': 0.30; 'work.': 0.31; "skip:' 10": 0.31; 'gary': 0.31; 'object.': 0.31; 'not.': 0.33; 'anybody': 0.35; 'convert': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'google': 0.35; 'there': 0.35; 'i.e.': 0.36; 'object,': 0.36; 'representing': 0.36; 'possible': 0.36; 'hi,': 0.36; 'should': 0.36; 'searching': 0.37; 'two': 0.37; 'list': 0.37; 'problems': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'full': 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'different': 0.65; 'talking': 0.65; 'between': 0.67; 'as:': 0.81; 'associations': 0.84; 'marzo': 0.84; 'this...': 0.84; 'absolutely': 0.87; 'hands': 0.96
X-Virus-Scanned OK
Date Sun, 05 Jan 2014 12:09:52 -0800
From Gary Herron <gary.herron@islandtraining.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: converting a string to a function parameter
References <aaf29677-db0b-4749-84b1-ce965e0f545e@v5g2000prm.googlegroups.com> <ef4ee1e8-e247-4fda-ae5f-439dd9742a75@googlegroups.com>
In-Reply-To <ef4ee1e8-e247-4fda-ae5f-439dd9742a75@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding quoted-printable
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.4965.1388952599.18130.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1388952599 news.xs4all.nl 2943 [2001:888:2000:d::a6]:55911
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63219

Show key headers only | View raw


On 01/05/2014 11:39 AM, 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...

Absolutely not.  Objects (like [654,54,65]) do not have names, never did 
and never will!  Objects do have a type and a value (and an identity), 
but not a name.

Various namespaces will have dictionary-like associations between a name 
(like "m") and an object, and it *is* possible to get your hands on a 
(dictionary representing a) namespace and search it, but this is 
troublesome.

For instance, consider this small variation of your code:

def function(m):
    return takethenameof(m)

a=[654,54,65]
b = a
function(a)

While function is running, there will be three names associated with the list object.
The outer namespace will have "a" and "b" associated with the list object,
and the namespace local to function will have "m" associated with the same object.
That's one object associated with three names in two different namespaces.

Gary Herron

Back to comp.lang.python | Previous | NextPrevious 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