Re: string to list when the contents is a list

2010-02-18 Thread nn
Wes James wrote: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] The [] is simple since I can just check if value == [] then return [] But with ['a','b'] I have tried and get: a=['a','b']

Re: string to list when the contents is a list

2010-02-18 Thread Tim Chase
Wes James wrote: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] The [] is simple since I can just check if value == [] then return [] But with ['a','b'] I have tried and get: a=['a','b']

Re: string to list when the contents is a list

2010-02-18 Thread Wes James
On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase python.l...@tim.thechases.com wrote: Wes James wrote: snip Just to add to the list of solutions I've seen, letting the built-in csv module do the heavy lifting:   s = ['a','b']   import csv   no_brackets = s[1:-1] # s.strip(' \t[]')   c =

Re: string to list when the contents is a list

2010-02-18 Thread Wes James
On Thu, Feb 18, 2010 at 12:32 PM, Wes James compte...@gmail.com wrote: On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase python.l...@tim.thechases.com wrote: Wes James wrote: snip Just to add to the list of solutions I've seen, letting the built-in csv module do the heavy lifting:   s =

Re: string to list when the contents is a list

2010-02-18 Thread Tim Chase
import csv class IS_LIST(): def __init__(self, format='', error_message='must be a list!'): self.format = format self.error_message = error_message def __call__(self, value): try: if value=='[]' or value=='': value=[] else:

Re: string to list when the contents is a list

2010-02-18 Thread Benjamin Kaplan
On Thu, Feb 18, 2010 at 2:56 PM, Wes James compte...@gmail.com wrote: I get an error (when I take the try out): AttributeError: 'function' object has no attribute 'reader' You have a function called csv that's defined after the import csv statement is executed. That function has no

Re: string to list when the contents is a list

2010-02-18 Thread Aahz
In article mailman.2736.1266522979.28905.python-l...@python.org, Wes James compte...@gmail.com wrote: try: if value=3D=3D'[]' or value=3D=3D'': value=3D[] else: no_brackets =3D value[1:-1] # s.strip(' \t[]') c =3D

Re: string to list when the contents is a list

2010-02-18 Thread Rhodri James
On Thu, 18 Feb 2010 14:52:29 -, nn prueba...@latinmail.com wrote: Wes James wrote: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] The [] is simple since I can just check if value == [] then

string to list when the contents is a list

2010-02-17 Thread Wes James
I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] The [] is simple since I can just check if value == [] then return [] But with ['a','b'] I have tried and get: a=['a','b'] b=a[1:-1].split(',')

Re: string to list when the contents is a list

2010-02-17 Thread Vlastimil Brom
2010/2/18 Wes James compte...@gmail.com: I have been trying to create a list form a string.  The string will be a list (this is the contents will look like a list).  i.e. [] or ['a','b'] The [] is simple since I can just check if value == [] then return [] But with ['a','b'] I have tried

Re: string to list when the contents is a list

2010-02-17 Thread Rhodri James
On Wed, 17 Feb 2010 23:48:38 -, Wes James compte...@gmail.com wrote: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] If your string is trusted (i.e. goes nowhere near a user), just eval() it.

Re: string to list when the contents is a list

2010-02-17 Thread Steven D'Aprano
On Thu, 18 Feb 2010 00:13:05 +, Rhodri James wrote: On Wed, 17 Feb 2010 23:48:38 -, Wes James compte...@gmail.com wrote: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] If your

Re: string to list when the contents is a list

2010-02-17 Thread Matt McCredie
Wes James comptekki at gmail.com writes: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] The [] is simple since I can just check if value == [] then return [] But with ['a','b'] I have

Re: string to list when the contents is a list

2010-02-17 Thread Ben Finney
Wes James compte...@gmail.com writes: I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. [] or ['a','b'] Pulling back to ask about the larger problem: Are you trying to create Python data structures from a