This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyRun_SimpleString won't parse \\x
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: effbot, gnupun
Priority: normal Keywords:

Created on 2006-01-30 07:43 by gnupun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg27386 - (view) Author: gnupun (gnupun) Date: 2006-01-30 07:43
I'm trying to use Python 2.4.2 from C on Win XP. 
The following line of C code generates an error:

test.c:
PyRun_SimpleString( "s = 'C:\\xyz'\n" );

Output:
ValueError: invalid \x escape


The error message only occurs if 'x' follows the 
slashes '\\x'. That is, no other letter causes this 
problem:

PyRun_SimpleString( "s = 'C:\\ayz'\n" );
PyRun_SimpleString( "s = 'C:\\yyz'\n" );

Using forward slashes also prevents the error:
PyRun_SimpleString( "s = "C:/xyz'\n" ); // ok
msg27387 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2006-01-30 16:16
Logged In: YES 
user_id=38376

> The following line of C code generates an error

C uses the same escape rules as Python, so your first
test snippet looks like "C:\xyz" to Python.  which is
is an invalid string literal, just as the message says.

see the Python language reference to details on string
literal syntax.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42849
2006-01-30 07:43:56gnupuncreate