Unsupported operand types in if/else list comprehension

Diez B. Roggisch deets at nospam.web.de
Sat Apr 11 07:38:01 EDT 2009


Mike H schrieb:
> Thanks to all of you.
> 
> FYI, I'm doing this because I'm working on creating some insert
> statements in SQL, where string values need to be quoted, and integer
> values need to be unquoted.
> 
> I wanted to be sure that I could pass these values to the list in a
> normal way e.g. ['test', 1, 'two'] and have a function correct the
> list for me, rather than calling the function with a strangely quoted
> list e.g. ['"'test'"', 1, '"'two'"'].> 

Don't do that yourself. This is error-prone. Instead, use the 
parametrized verison of the cursor.execute-method. It will perform the 
necessary escaping, and depending on the database and database adapter 
you use better performance.

Diez



More information about the Python-list mailing list