Alex Rivera | Logout

A good way to escape quotes in a database query string?

Asked 2009-05-22T09:16:28.807
47

I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?

Edit
Report

1 Answer

24

Use json.dumps.

>>> import json
>>> print json.dumps('a"bc')
"a\"bc"
answered 2013-02-18T06:25:16.757

Your Answer