struct unpack

Michael Wieher michael.wieher at gmail.com
Mon Mar 17 21:15:28 CET 2008


>
> testValue = '\x02\x00'
> junk = struct.unpack('h', testValue)  #Works
>
> testValue = raw_input("Enter Binary Code..:")  inputting at the
> console '\x02\x00'
> junk = struct.unpack('h', testValue)
>
> error: unpack requires a string argument of length 2


Well, it thinks the length of the testValue is longer than 2.
Why not print out len(testValue) immediately after calling raw_input?
maybe raw_input doesn't recognize hex-values automatically, while a
string='\x??' is recognizable by the interpreter as such.

obviously the issue is raw_input and how it handles input strings... how to
fix?  no idea =)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080317/357e9052/attachment.html>


More information about the Python-list mailing list