473,772 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('\x0 0\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 1597
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('\x 00\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
6606
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, it's a bit kludgy but it gets the right results. Thanks in advance.
3
15876
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 : "\\x20\\x01\\x21"
3
9512
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 the end of this message is the inflate method this is where I get stuck I know that I need a byte array but because I am decompressing a string I have no idea of how big the byte array will need to be in the end (the inflate and deflate methods...
8
4367
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
991
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 <ewijaya@i2r.a-star.edu.sg> On 10/27/06, Wijaya Edward <ewijaya@i2r.a-star.edu.sgwrote: \xXX just internal representation of None ASCII, I guess above string is encoded with local locale, maybe gbk. You can get the bytes list
5
1796
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 part of the style rule needed to draw VML images. This is my current code at the moment: var theTextofStyle = document.createTextNode('v\:* { behavior: url(#default#VML); }'); document.getElementsByTagName('style').appendChild(theTextofStyle);
11
3595
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 Read_bin(ByVal ruta As String) Dim cadena As String = "" Dim dato As Array If File.Exists(ruta) = True Then
3
23013
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) replaced, but the second is not ??? Is it in general better to use double backslash in filepaths ? thanks, Stef Mientki
1
1635
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? i.e. if I access pair on my linux server, do I have to put a forward slash in between Mail and mime? such as Mail/
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.