Dies ist ein einfaches Beispiel:Anruffunktionen von re.sub
import re
math='<m>3+5</m>'
print re.sub(r'<(.)>(\d+?)\+(\d+?)</\1>', int(r'\2') + int(r'\3'), math)
Es gibt mir diese Fehlermeldung:
ValueError: invalid literal for int() with base 10: '\\2'
Es sendet \\2
statt 3
und 5
.
Warum? Wie löse ich es?
Mögliches Duplikat [Python Bespannbild ersetzen mit Ausgabe der Funktion] (http://stackoverflow.com/questions/12597370/python-replace-string-pattern-with-output-of-function) – thakis