libnum.n2s也有相同的效果,打字也更方便
long_to_bytes(n, blocksize=0)
正整数转化为byte类型字符串
Convert a positive integer to a byte string using big endian encoding.
If :data:`blocksize` is absent or zero, the byte string will
be of minimal length.
Otherwise, the length of the byte string is guaranteed to be a multiple
of :data:`blocksize`. If necessary, zeroes (``\x00``) are added at the left.
.. note::
In Python 3, if you are sure that :data:`n` can fit into
:data:`blocksize` bytes, you can simply use the native method instead::
>>> n.to_bytes(blocksize, 'big')
For instance::
>>> n = 80
>>> n.to_bytes(2, 'big')
b'\x00P'
However, and unlike this ``long_to_bytes()`` function,
an ``OverflowError`` exception is raised if :data:`n` does not fit.