If I run:
testValue = '\x02\x00'
junk = struct.unpack('h', testValue)
Everything works but If I run
testValue = raw_input("Enter Binary Code..:") inputting at the
console '\x02\x00'
junk = struct.unpack('h', testValue)
It errors out with
Traceback (most recent call last):
File "/home/nirmal/eDoseCheck/yennes1.py", line 9, in <module>
junk = struct.unpack('h', testValue)
File "struct.py", line 87, in unpack
return o.unpack(s)
error: unpack requires a string argument of length 2
any ideas? 2 4370
On Mar 17, 11:00 pm, brnstrmrs <brnstr...@gmail.comwrote:
If I run:
testValue = '\x02\x00'
junk = struct.unpack('h', testValue)
Everything works but If I run
testValue = raw_input("Enter Binary Code..:") inputting at the
console '\x02\x00'
junk = struct.unpack('h', testValue)
It errors out with
Traceback (most recent call last):
File "/home/nirmal/eDoseCheck/yennes1.py", line 9, in <module>
junk = struct.unpack('h', testValue)
File "struct.py", line 87, in unpack
return o.unpack(s)
error: unpack requires a string argument of length 2
any ideas?
You may need to use eval, because raw_input() does not understand '\'-
prefixed characters.
>>testValue = eval('"%s"' % raw_input("Enter Binary Code..: "))
Enter Binary Code..: \x02\x00
>>junk, = struct.unpack('h', testValue) print junk
2
"brnstrmrs" <br*******@gmail.comwrote in message
news:18**********************************@u72g2000 hsf.googlegroups.com...
If I run:
testValue = '\x02\x00'
junk = struct.unpack('h', testValue)
Everything works but If I run
testValue = raw_input("Enter Binary Code..:") inputting at the
console '\x02\x00'
junk = struct.unpack('h', testValue)
It errors out with
Traceback (most recent call last):
File "/home/nirmal/eDoseCheck/yennes1.py", line 9, in <module>
junk = struct.unpack('h', testValue)
File "struct.py", line 87, in unpack
return o.unpack(s)
error: unpack requires a string argument of length 2
any ideas?
raw_input doesn't understand escape sequences. You have to decode them.
import struct
testValue=raw_input() # input '\x02\x00'
junk = struct.unpack('h',testValue.decode('string_escape' ))
--Mark This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Josiah Carlson |
last post by:
Good day everyone,
I have produced a patch against the latest CVS to add support for two
new formatting characters in the struct module. It is currently an RFE,
which I include a link to at the...
|
by: Geoffrey |
last post by:
Hope someone can help.
I am trying to read data from a file binary file and then unpack the
data into python variables. Some of the data is store like this;
xbuffer:...
|
by: grant |
last post by:
Hi All,
I am pretty new to python and am having a problem
intepreting binary data using struct.unpack.
I am reading a file containing binary packed data
using open with "rb". All the values are...
|
by: Alfonso Morra |
last post by:
Hi,
I am at the end of my tether now - after spending several days trying to
figure how to do this. I have finally written a simple "proof of
concept" program to test serializing a structure...
|
by: Giovanni Bajo |
last post by:
Hello,
given the ongoing work on struct (which I thought was a dead module), I was
wondering if it would be possible to add an API to register custom parsing
codes for struct. Whenever I use it...
| |
by: David Bear |
last post by:
I found this simple recipe for converting a dotted quad ip address to a
string of a long int.
struct.unpack('L',socket.inet_aton(ip))
trouble is when I use this, I get
struct.error: unpack...
|
by: OhKyu Yoon |
last post by:
Hi!
I have a really long binary file that I want to read.
The way I am doing it now is:
for i in xrange(N): # N is about 10,000,000
time = struct.unpack('=HHHH', infile.read(8))
# do...
|
by: Ping Zhao |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I am writing a small program to decode MS bitmap image. When I use statements as follow, it works fine:
header = str(struct.unpack('2s',...
|
by: Heikki Toivonen |
last post by:
M2Crypto has some old code that gets and sets socket timeouts in
http://svn.osafoundation.org/m2crypto/trunk/M2Crypto/SSL/Connection.py,
for example:
def get_socket_read_timeout(self):
return...
|
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,...
|
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,...
| |
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...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |