hexstring to string?

Antaeus Feldspar feldspar at ix.netcom.com
Thu Mar 7 15:25:52 EST 2002


maximilianscherr wrote:

> i made a function to convert a hex string containing character to a 
> normal string.
> 
> it looks like this:
> 
> class ConversionHandler:
>     def ConvertHexToStr(self, hex):
>         letter = 0
>         str = ''
>         while len(str) < len(hex) / 2:
>             nextletter = letter + 2
>             str = str + chr(int(hex[letter:nextletter], 16))
>             letter = nextletter
> 
>         return str
> 
> hex looks like: 414243
> 
> but why does it not work?


Some possibilities:

* You are using a version of Python earlier than 1.6; previous to 1.6, 
int() took one and only one argument.  If this is the case, you can use 
string.atoi with the same interface.

* You are passing in an integer rather than a string(414243 rather than 
'414243'), in which case len(hex) will fail because an integer is an 
unsized object.

* You are not creating an instance of ConversionHandler and passing the 
argument to the instance to perform the work.  (Why are you making it an 
object method, anyhow?)




More information about the Python-list mailing list