Movatterモバイル変換


[0]ホーム

URL:


simulate backslash substitution identical to python parser

Harald Kirschkirschh at lionbioscience.com
Tue Apr 24 10:55:28 EDT 2001


Setting: A function generates a string containing a regular expression. Thestring must be used in two fashions:1) It is printed into a file which contains python code to be laterexecuted. 2) It must be used immediately as a regexp.For (1) backslashes must be escaped themselves several times, e.g.  space1 = "\\\\s"             # space now contains two backslashes  print "space2 = '"+space1+"'"The resulting text contains then  space2 = '\\s'               # (*)and consequently variable space2 will contain just one backslash.Question:Given that I have space1, is there a function which does the sametranslation as does the python interpreter when interpreting/compilingthe line (*) such that in this case I end up with just one backslash?Problem: Working with raw strings is currently not an option.Thanks,  Harald Kirsch-- ----------------+------------------------------------------------------Harald Kirsch   |kirschh at lionbioscience.com | "How old is the epsilon?"LION bioscience | +49 6221 4038 172          |        -- Paul Erdös       *** Please do not send me copies of your posts. ***


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp