473,398 Members | 2,404 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,398 software developers and data experts.

backslash in reading bytes

I am trying to read some byte data as a string then using a library to
convert them a code:
>>>reader = csv.DictReader(open('table.txt'))
def eleFind(value):
for row in reader:
if row['byteCode'] == value:
print row['Element']
return
else:
print "No Match Found:"
eleFind('\x00\x00')
My table contains:

\x00\x00,0000
\x01\x00,0000
.......

The program errors out. How can I fix/overide this backslash issue.
Mar 20 '08 #1
1 1576
On Thu, 20 Mar 2008 03:24:49 -0700, Dravidan wrote:
I am trying to read some byte data as a string then using a library to
convert them a code:
>>>>reader = csv.DictReader(open('table.txt'))
def eleFind(value):
for row in reader:
if row['byteCode'] == value:
print row['Element']
return
else:
print "No Match Found:"
eleFind('\x00\x00')

My table contains:

\x00\x00,0000
\x01\x00,0000
......

The program errors out. How can I fix/overide this backslash issue.
What does `errors out` mean?

It won't find two zero bytes. What you give at the `eleFind()` call are
just *two* characters with a byte value of zero:

In [116]: len('\x00\x00')
Out[116]: 2

In [117]: print '\x00\x00'
In [118]: len('\\x00\\x00')
Out[118]: 8

In [119]: print '\\x00\\x00'
\x00\x00

The backslash has a special meaning in string literals. If you don't want
this meaning, you have to escape it with another backslash.

Ciao,
Marc 'BlackJack' Rintsch
Mar 20 '08 #2

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

Similar topics

6
by: Dietrich Epp | last post by:
Are there any good modules for reading a bitstream? Specifically, I have a string and I want to be able to get the next N bits as an integer. Right now I'm using struct.unpack and bit operations,...
3
by: Vincent Texier | last post by:
Hello, I want to send 3 chars in hexa code to the serial port. So I type in a tkinter entry : "\x20\x01\x21" The string is set in a StringVar(). When I read the stringVar, I get :...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
8
by: Wijaya Edward | last post by:
Hi all, I was trying to split a string that represent chinese characters below: ??? But why the split function here doesn't seem
0
by: limodou | last post by:
---------- Forwarded message ---------- From: limodou <limodou@gmail.com> Date: Oct 27, 2006 11:51 AM Subject: Re: How to Split Chinese Character with backslash representation? To: Wijaya Edward...
5
by: Yansky | last post by:
Hi, I'm trying to write a backslash as a text node into the style tag of a web page, but IE is not letting me(perhaps because of security or something?). I need to write a backslash because it is...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
1
by: cybervigilante | last post by:
I was trying the pear package on my local winmachine and noticed that one of the includes has a backslash <?php include('Mail.php'); include('Mail\mime.php'); is this a path backslash?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.