473,287 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

ValueError: invalid \x escape

I wrote a python code in linux text pad and copied to thumb drive and
try to ran the file by changing the path to windows:

sys.path = sys.path + ['D:\Python24\Lib\site-packages\mycode]

I get the following error:

ValueError: invalid \x escape

I am pretty sure this problem is due some kind of linux end of line
markers or escape characters that windows os doesn't understand. Is
there a way to fix this?

Nov 2 '07 #1
1 19140
crybaby wrote:
I wrote a python code in linux text pad and copied to thumb drive and
try to ran the file by changing the path to windows:

sys.path = sys.path + ['D:\Python24\Lib\site-packages\mycode]

I get the following error:

ValueError: invalid \x escape

I am pretty sure this problem is due some kind of linux end of line
markers or escape characters that windows os doesn't understand. Is
there a way to fix this?

You have two errors in your code. The first is that you didn't close
your quotes. However, that wouldn't cause a value error, so you
probably introduced that one in your email. The other is that you
haven't escaped your backslashes. Python, unlike many other scripting
languages, does not distinguish between single and double quotes (except
insofar as there may be single or double quotes within the string, of
course), so python sees a \P, a \L a \s, and a \m in your string. There
are two ways to solve this:

1) Use a raw string: r'D:\Python24\Lib'
2) Escape your backslashes: 'D:\\Python24\\Lib'

I assume the real value of 'mycode' has an x immediately after a \, right?

Cheers,
Cliff
P.S. I just got my crystal ball back from the cleaners, so I can guess
some of what you haven't told us, but in the future, make sure the code
you post exhibits the problem you see. Use copy and paste instead of
retyping, and if you change the code, make sure the changed code still
exhibits the same problems.
Nov 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
12
by: Aki Niimura | last post by:
Hello everyone, I started to use pickle to store the latest user settings for the tool I wrote. It writes out a pickled text file when it terminates and it restores the settings when it starts....
1
by: Martin MOKREJ© | last post by:
Hi, is this a bug or "feature" that I have to use float() to make int() autoconvert from it? $ python Python 2.3.4 (#1, Feb 14 2005, 10:00:27) on linux2 Type "help", "copyright", "credits"...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
0
by: philip20060308 | last post by:
Hi all, Has anyone ever seen Python 2.4.1's httplib choke when reading chunked content? I'm using it via urrlib2, and I ran into a particular server that returns something that httplib doesn't...
1
by: alain MONTMORY | last post by:
Hello everybody, I am a newbie to python so I hope I am at the right place to expose my problem..... :-http://www.python.org/doc/2.4.2/ext/pure-embedding.html 5.3 Pure Embedding I download the...
2
by: abcd | last post by:
I have the following code which is sent over the wire as a string... from time import time class Foo: def go(self): print "Time:", time() I get this code and store it as, "data"
1
Eclipse
by: Eclipse | last post by:
G'day all In the code below I am trying to catch an error thrown if i enter any other value than an integer. (I used the string 'six' and the float '1.5') The error thrown in the command...
11
by: davidj411 | last post by:
i am parsing a cell phone bill to get a list of all numbers and the total talktime spend on each number. i already have a unique list of the phone numbers. now i must go through the list of...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.