Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25658

Re: help

Date 2012-07-19 18:14 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: help
References <E11474306C04254C871D4C0B6AE5CA6F1E81F8BF@SN2PRD0202MB131.namprd02.prod.outlook.com>
Newsgroups comp.lang.python
Message-ID <mailman.2324.1342739610.4697.python-list@python.org> (permalink)

Show all headers | View raw


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


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: help Tim Chase <python.list@tim.thechases.com> - 2012-07-19 18:14 -0500

csiph-web