[Python] e = lp.parse(r'\x.(walk(x) & chew_gum(x))') -> ValueError: invalid \x escape

Marco Ippolito ippolito.marco a gmail.com
Mar 14 Gen 2014 09:56:47 CET


Ciao a tutti,
seguendo le indicazioni trovate qui: http://nltk.org/book/ch10

ho scritto le seguenti righe di codice:
lp = nltk.LogicParser()
e = lp.parse(r'\x.(walk(x) & chew_gum(x))')
print

output: ValueError: invalid \x escape

Nel libro "Learning Python:5th Edition" ho trovato:
"Python allows strings to be enclosed in single or double quote
characters—they mean
the same thing but allow the other type of quote to be embedded with
an escape (most programmers prefer single quotes). It also allows
multiline string literals enclosed in triple quotes (single or
double)—when this form is used, all the lines are concatenated
together, and end-of-line characters are added where line breaks
appear. This is a minor syntactic convenience, but it’s useful for
embedding things like multiline HTML, XML, or JSON code in a Python
script.
Python also supports a raw string literal that turns off the backslash
escape mechanism.
Such literals start with the letter r and are useful for strings like
directory paths on
Windows (e.g., r'C:\text\new')."

Per cui sembrerebbe che abbia scritto correttamente.

Consigli e suggerimenti  per risolvere la situazione (ValueError:
invalid \x escape)?

Vi ringrazio per l'aiuto..
Marco


Maggiori informazioni sulla lista Python