help

Tim Chase python.list at tim.thechases.com
Thu Jul 19 19:14:33 EDT 2012


On 07/19/12 17:31, Miriam Gomez Rios wrote:
> Hello, sorry for bothering you, but I have a doubt,
> 
> Is there a way to turn this string into a tuplelist??????, I
> need it for gurobi
> 
> ('per1','persona1.1','pro1'),('per1','persona1.1','pro2'),('per1','persona1.1','pro3'),...,('per2','persona2.4','pro3'

Assuming a closing paren, you can safely use ast.literal_eval on the
raw string:

  import ast
  s = "('per1','persona1.1','pro1'),('per1','persona1.1','pro2')"
  resulting_tuple_of_tuples = ast.literal_eval(s)

-tkc






More information about the Python-list mailing list