mercredi 1 avril 2015

Python putting r before unicode string variable

For static strings, putting an r in front of the string would give the raw string (e.g. r'some \' string'). Since it is not possible to put r in front of a string variable, what is the minimal approach to dynamically convert a string variable to its raw form? Should I manually substitute all backslashes with double backslashes?



str_var = u"some text with escapes e.g. \( \' \)"
raw_str_var = ???

Aucun commentaire:

Enregistrer un commentaire