backslash in reading bytes

2008-03-20 Thread Dravidan
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,
\x01\x00,
..

The program errors out.  How can I fix/overide this backslash issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv dictreader

2008-03-20 Thread Dravidan
It looks like the backslash is messing the whole thing up so I
reposted to try to find out how to get over the backslash hump.


On Mar 20, 2:08 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Wed, 19 Mar 2008 11:06:40 -0700 (PDT), brnstrmrs
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> > my csv files looks like this:
>
> > Bytecode,Element
> > \x00\x00,
> > \x01\x00,0001
> > 
> > \x09\x00,0009
>
> I sure hope your data is more complex than that... otherwise it's a
> waste of space...
>
>  >>> for i in range(10):
> ... print i, repr(struct.pack("h", i))
> ...
> 0 '\x00\x00'
> 1 '\x01\x00'
> 2 '\x02\x00'
> 3 '\x03\x00'
> 4 '\x04\x00'
> 5 '\x05\x00'
> 6 '\x06\x00'
> 7 '\x07\x00'
> 8 '\x08\x00'
> 9 '\t\x00'
>
> And, \t is the same value \x09 (a tab character)
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED][EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

-- 
http://mail.python.org/mailman/listinfo/python-list