string to list when the contents is a list

Aahz aahz at pythoncraft.com
Thu Feb 18 22:18:51 CET 2010


In article <mailman.2736.1266522979.28905.python-list at python.org>,
Wes James  <comptekki at 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 csv.reader([no_brackets], quotechar=3D"'")
>		value=3Dc.next()
>            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
problems
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"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