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

creating a hex value

I have a file that I need to parse. Items in it are delimited by a hex 15
(0x015). I know it must be trivial to assign a hex value to a variable but
I'm not seeing it in my python essential ref. how can I do

delim = 0x15
while:
ln = file.read()
if ln[0] == delim:
do something

I've looked at the hex function but it doesn't sound like what I want.

--
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
Jul 19 '05 #1
6 5800
David Bear <da********@asu.edu> writes:
I'm not seeing it in my python essential ref. how can I do

delim = 0x15


delim = chr(0x15)
Jul 19 '05 #2
What about

martin@lijnbaansgracht:~$ python
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
hex(21) '0x15'


Jul 19 '05 #3
Paul Rubin wrote:
David Bear <da********@asu.edu> writes:
I'm not seeing it in my python essential ref. how can I do

delim = 0x15

delim = chr(0x15)


Ooooh -- a function with a constant arg; I wonder what that evaluates to?
chr(0x15)

'\x15'

Sheeeesh.
Jul 19 '05 #4
wi******@hotmail.com wrote:
What about

martin@lijnbaansgracht:~$ python
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
hex(21)
'0x15'

len('0x15')

4

Quadruple sheeeeeeeeeeeeeesh.

Jul 19 '05 #5
John Machin wrote:
delim = chr(0x15)


Ooooh -- a function with a constant arg; I wonder what that evaluates to?
>>> chr(0x15) '\x15'

Sheeeesh.


OK, let's double-check that:
chr(0x15) 'The argument is constant -- but not necessarily the /function/.'


Sheeeesh :-)

Peter

Jul 19 '05 #6
David Bear wrote:
I have a file that I need to parse. Items in it are delimited by a hex 15
(0x015). I know it must be trivial to assign a hex value to a variable but
I'm not seeing it in my python essential ref. how can I do

delim = 0x15
while:
ln = file.read()
if ln[0] == delim:
do something

I've looked at the hex function but it doesn't sound like what I want.


you can use use

ord(ln[0]) == delim

or

ln[0] == '\x15'

or

ln[0] == chr(delim)

or

ln.startswith("\x015")

or some other variation.

fwiw, I'm pretty sure file.read() doesn't do what you want either (unless
you're 100% sure that the file only contains a single item).

if the file isn't larger than a few megs, consider using

items = file.read().split("\x15")

</F>

Jul 19 '05 #7

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

Similar topics

6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
7
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
5
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function...
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: 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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.