Re: How to convert a string into a list

2010-10-05 Thread Matteo Landi
What about using the json library? It could handle errors for you: >>>import json >>>s = '["1", "2"]' >>>json.loads(s) [u'1', u'2'] Now you can convert then to integer values. Best regards, Matteo On Tue, Oct 5, 2010 at 3:41 PM, Mark Phillips wrote: > Thanks to everyone for their suggestions.

Re: How to convert a string into a list

2010-10-05 Thread Mark Phillips
Thanks to everyone for their suggestions. I learned a lot from them! Mark On Mon, Oct 4, 2010 at 11:54 PM, Chris Rebert wrote: > On Mon, Oct 4, 2010 at 10:33 PM, Arnaud Delobelle > wrote: > > MRAB writes: > >> On 05/10/2010 02:10, Mark Phillips wrote: > >>> I have the following string - "['1'

Re: How to convert a string into a list

2010-10-04 Thread Chris Rebert
On Mon, Oct 4, 2010 at 10:33 PM, Arnaud Delobelle wrote: > MRAB writes: >> On 05/10/2010 02:10, Mark Phillips wrote: >>> I have the following string - "['1', '2']" that I need to convert into a >>> list of integers - [1,2]. The string can contain from 1 to many >>> integers. Eg "['1', '7', '4',..

Re: How to convert a string into a list

2010-10-04 Thread Arnaud Delobelle
MRAB writes: > On 05/10/2010 02:10, Mark Phillips wrote: >> I have the following string - "['1', '2']" that I need to convert into a >> list of integers - [1,2]. The string can contain from 1 to many >> integers. Eg "['1', '7', '4',..,'n']" (values are not sequential) >> >> What would be the

Re: How to convert a string into a list

2010-10-04 Thread MRAB
On 05/10/2010 02:10, Mark Phillips wrote: I have the following string - "['1', '2']" that I need to convert into a list of integers - [1,2]. The string can contain from 1 to many integers. Eg "['1', '7', '4',..,'n']" (values are not sequential) What would be the best way to do this? I don't

Re: How to convert a string into a list

2010-10-04 Thread Steven D'Aprano
On Tue, 05 Oct 2010 11:25:58 +1000, James Mills wrote: > On Tue, Oct 5, 2010 at 11:10 AM, Mark Phillips > wrote: >> I have the following string - "['1', '2']" that I need to convert into >> a list of integers - [1,2]. The string can contain from 1 to many >> integers. Eg "['1', '7', '4',..,'n

Re: How to convert a string into a list

2010-10-04 Thread Chris Rebert
On Mon, Oct 4, 2010 at 6:25 PM, James Mills wrote: > On Tue, Oct 5, 2010 at 11:10 AM, Mark Phillips > wrote: >> I have the following string - "['1', '2']" that I need to convert into a >> list of integers - [1,2]. The string can contain from 1 to many integers. Eg >> "['1', '7', '4',..,'n']"

Re: How to convert a string into a list

2010-10-04 Thread Chris Rebert
On Mon, Oct 4, 2010 at 6:10 PM, Mark Phillips wrote: > I have the following string - "['1', '2']" that I need to convert into a > list of integers - [1,2]. The string can contain from 1 to many integers. Eg > "['1', '7', '4',..,'n']" (values are not sequential) > > What would be the best way t

Re: How to convert a string into a list

2010-10-04 Thread James Mills
On Tue, Oct 5, 2010 at 11:10 AM, Mark Phillips wrote: > I have the following string - "['1', '2']" that I need to convert into a > list of integers - [1,2]. The string can contain from 1 to many integers. Eg > "['1', '7', '4',..,'n']" (values are not sequential) > > What would be the best way

How to convert a string into a list

2010-10-04 Thread Mark Phillips
I have the following string - "['1', '2']" that I need to convert into a list of integers - [1,2]. The string can contain from 1 to many integers. Eg "['1', '7', '4',..,'n']" (values are not sequential) What would be the best way to do this? I don't want to use eval, as the string is coming fr