get a list from a string

half.italian at gmail.com half.italian at gmail.com
Thu Jun 7 06:50:34 EDT 2007


On Jun 7, 3:34 am, simon kagwe <simonka... at yahoo.com> wrote:
> Hi,
>
> I have a string "distances = [[1,1,1,1],[2,2,2,2]]". I want to create a
> variable called distances whose value is the list [[1,1,1,1],[2,2,2,2]]. How can
> I go about that? I know I can use setattr, but how do I create the list from the
> string?
>
> Regards,
> Simon

exec("distances = [[1,1,1,1],[2,2,2,2]]")

~Sean




More information about the Python-list mailing list