struct unpack

Michael Wieher michael.wieher at
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: <>

More information about the Python-list mailing list