String to sequence

Peter Otten __peter__ at web.de
Sat Mar 14 06:44:35 EDT 2009


mattia wrote:

> Il Sat, 14 Mar 2009 10:30:43 +0100, Vlastimil Brom ha scritto:
> 
>> 2009/3/14 mattia <gervaz at gmail.com>:
>>> How can I convert the following string:
>>>
>>> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
>>> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ'
>>>
>>> into this sequence:
>>>
>>> ['AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
>>> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ']
>>>
>>> Thanks a lot,
>>> Mattia
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>> Apart from the "obvious" and rather discouraged
>>>>> list(eval("'AAR','ABZ','AGA','AHO'"))
>> ['AAR', 'ABZ', 'AGA', 'AHO']
> 
> Why discouraged?

The guys controlling the website you are scraping could feed you something
you didn't expect, e. g.:

supposed_to_be_flight_codes = "__import__('os').system('rm whatever')"
eval(supposed_to_be_flight_codes) # oops, crash landing


Peter



More information about the Python-list mailing list