string to list when the contents is a list

Aahz aahz at
Thu Feb 18 22:18:51 CET 2010

In article <mailman.2736.1266522979.28905.python-list at>,
Wes James  <comptekki at> wrote:
>        try:
>            if value=3D=3D'[]' or value=3D=3D'':
>            	value=3D[]
>            else:
>            	no_brackets =3D value[1:-1] # s.strip(' \t[]')
>            	c =3D csv.reader([no_brackets], quotechar=3D"'")
>            return (value, None)
>        except:
>            return (value, self.error_message)

Two important points:

* Don't use bare except: clauses

* Put less code in the try: clause to make it easier to track down
Aahz (aahz at           <*>

"At Resolver we've found it useful to short-circuit any doubt and just        
refer to comments in code as 'lies'. :-)"

More information about the Python-list mailing list