Elegent solution to replacing ' and " ?

fyleow fyleow at gmail.com
Fri May 5 19:46:55 EDT 2006


I'm trying to replace the ' and " characters in the strings I get from
feedparser so I can enter it in the database without getting errors.
Here's what I have right now.

self.title = entry.title.encode('utf-8')
self.title = self.title.replace('\"', '\\\"')
self.title = self.title.replace('\'', '\\\'')

This works just great but is there a more elegent way to do this?  It
looks like maybe I could use the translate method but I'm not sure.




More information about the Python-list mailing list