sorry for this stupid question about struct module
aleax at aleax.it
Fri Sep 20 09:32:47 CEST 2002
Alan Marchand wrote:
> Hi all,
> I tryed this :
> Python 2.2.1 ( #34, Apr 9 2002, ...................)
>>>> import struct
>>>> x = struct.pack( '>I', 10 )
>>>> print repr( x )
> '\x00\x00\x00\n' # why not !
> How can I obtain the result a expect : '\x00\x00\x00\0A' ?
If you need a specific repr that ignores the possibility of
representing some characters otherwise than as hex escapes,
I think you'll have to code it yourself -- most particularly
so if you want some hex escapes to have the x (as in the \x00
occurrences above) and others to lack it (as in the \0A above):
how would any standard repr ever be able to guess these reqs?!
I don't understand why you need such a weird repr. What are
you going to do with it? x is a 4-byte string made up of bytes
with numerical values 0, 0, 0, 10 -- repr shows the latter as
\n, of course, since 10 is the value of \n -- but why is repr's
behavior problematic to you?
> Remark :
> This, to send a message to a IBM Mainframe in order to start an IMS
> transaction ( via IMS CONNECT ).
You won't use repr for the purpose of sending that message,
thus I'm more and more perplexed about why you think there's
a problem here. String x does seem to be what you want to send.
More information about the Python-list