[Tutor] Conversion question

spir denis.spir at free.fr
Tue May 5 11:33:41 CEST 2009


Le Tue, 5 May 2009 00:52:11 +0100,
"Alan Gauld" <alan.gauld at btinternet.com> s'exprima ainsi:

> > Is there a way in Python to say this is a string of HEX characters like
> > Perl's pack?  Right now I have to take the string and add a \x to every 
> > two
> > values i.e. \x41\x42...  
> 
> Assuming you actually want to send the hex values rather than
> a hex string representation then the way I'd send that would be
> to convert that to a number using int() then transmit it using
> struct()

I can hardly imagine why you want an hex string representation for further process instead of the values, neither. Would be interested in the reason for this.
Assuming that an interface require hex string, wouldn't it be easier to change this so that it directly gets values? Id est avoid double format conversion.

Denis
------
la vita e estrany


More information about the Tutor mailing list