From: Philip J. <pj...@un...> - 2012-06-02 19:43:04
|
On Jun 2, 2012, at 5:50 AM, Walter Chang wrote: > Hi All - > > I'm migrating some code from java to jython and am having some > problems understanding how to translate the following: > > byte[] salt = { (byte) 0xA5, (byte) 0x9E, (byte) 0xD8, (byte) 0x36, > (byte) 0x26, (byte) 0x99, (byte) 0xEE, (byte) 0xB3 }; > > Below is what the code is based on: You can get an array of Java bytes underneath via: from array import array salt = array('b', [0xA5, 0x9E, ...]) However the array type is stricter about the values passed to it than the line of Java you pasted (as you'd get this error): OverflowError: value too large for byte That line of Java is actually explicitly converting your ints (the hex literals) to bytes via the cast. If you want to programmatically support passing values like this to the array type you would need to do the same conversion manually beforehand salt = array('b', (int2byte(i) for i in [0xA5, 0x9E, ...])) # the proper impl of int2byte escapes me now.. Or just pick salt values that already fit in the first place =] -- Philip Jenvey |