473,385 Members | 1,925 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,385 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 19162
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.