Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63217
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Subject | Re: converting a string to a function parameter |
| Date | 2014-01-05 14:58 -0500 |
| References | <aaf29677-db0b-4749-84b1-ce965e0f545e@v5g2000prm.googlegroups.com> <ef4ee1e8-e247-4fda-ae5f-439dd9742a75@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4963.1388951905.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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