get a list from a string

Josef Dalcolmo Josef.Dalcolmo at gmx.net
Thu Jun 7 12:49:54 CEST 2007


simon kagwe 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?

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

- Josef




More information about the Python-list mailing list