converting a string to a function parameter

odeits odeits at gmail.com
Fri Mar 13 09:19:37 EDT 2009


On Mar 13, 12:52 am, koranthala <koranth... at gmail.com> wrote:
> 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?

If the string has all of the names you could parse it into a
dictionary and pass it as the keyword arguments



More information about the Python-list mailing list