simulate backslash substitution identical to python parser

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


Setting: 
A function generates a string containing a regular expression. The
string must be used in two fashions:
1) It is printed into a file which contains python code to be later
executed. 
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 same
translation as does the python interpreter when interpreting/compiling
the 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-list mailing list