efficient mega-replacements

Clark C . Evans cce at clarkevans.com
Wed Jan 23 14:36:17 EST 2002


Is there an efficient way to do multiple replacements?

            val = val.replace("'","''")\
                     .replace("\\","\\\\\\\\\\\\\\\\")\
                     .replace(chr(13)+chr(10),"\\\\\\\\n")\
                     .replace(chr(10),"\\\\\\\\n")\
                     .replace(chr(13),"\\\\\\\\n")\
                     .replace('"','\\\\"')

Or is this the best way to do it?

Best,

Clark




More information about the Python-list mailing list