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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 01/05/2014 11:39 AM, pietrodcof@gmail.com wrote: > Il giorno venerd=EC 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 =3D 'True, type=3Drect, sizes=3D[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=3Drect, sizes=3D[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=3D[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 abou= t 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),=20 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=20 (dictionary representing a) namespace and search it, but this is=20 troublesome. For instance, consider this small variation of your code: def function(m): return takethenameof(m) a=3D[654,54,65] b =3D 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 sam= e object. That's one object associated with three names in two different namespaces= =2E Gary Herron