Java Integer.ParseInt translation to python

jicman jicman at gmail.com
Wed Feb 9 12:45:33 EST 2005


Nick Craig-Wood wrote:
> When I try your code I get this...
...
[clip]
...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 4, in PrepareHash
> TypeError: 'str' object is not callable
> >>>
>
> You cant do byte(int(byte,16)) - byte is a string!  So you haven't
> posted the actual code you ran...

you're right... What I ran was this:

def PrepareHash(HashStr):
  while len(HashStr) > 0:
    byte = HashStr[0:2]
    print byte,int(byte,16),chr(int(byte,16)) # & 0xff
    HashStr = HashStr[2:]
  return byte

def Main():
  HashStr = "c17ce186ab94eeb0de8ae3b5b751a7c4d8e9edeb"
  HashStr = PrepareHash(HashStr)
  print "Prepared HashStr :",HashStr

Main()


> Java bytes are signed also just to add to the confusion.

Exactly... which is the problem.  I don't know what the heck the [byte]
in front of a variable does.  I may have to get into the java list.
YUK!

thanks.

josé




More information about the Python-list mailing list