Fold All / Expand All

2008年2月2日 星期六

stripslashes() for Python

In PHP, we have stripslashes() and addslashes(). In Python, addslashes() is similar to re.escape(). The difference is re.escape() would return string with all non-alphanumerics backslashed when addslashes() only adds backslashes before single quote('), double quote("), backslash(\) and NUL (the NULL byte).

The following code can perform the same effect of stripslashes()re.sub(r'\\(.)', r'\1', string)

沒有留言: