[Tutor] string to list

Christian Witts cwitts at compuscan.co.za
Wed Feb 10 13:19:00 CET 2010


Owain Clarke wrote:
> Please excuse the obviousness of my question (if it is), but I have 
> searched the documentation for how to generate a list e.g. [(1,2), 
> (3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point 
> me in the right direction.
>
> Many thanks
>
> Owain Clarke
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
new_list = eval("[(1,2), (3,4)]")
But only ever do that if you know your incoming data is clean and 
secure, and even then I would be really careful with its usage.

If I remember correctly there was a recipe for safe parsing on 
http://code.activestate.com/ but I don't seem to have the link at hand.

-- 
Kind Regards,
Christian Witts




More information about the Tutor mailing list