Nagy László Zsolt wrote:
>
>>> bytes/str.ljust()
>>>
>> def pad(b, n=16, c=b"\x0f"):
>>> ... length = (len(b)+n-1)//n*n
>>> ... return b.ljust(length, c)
>> Thanks!
> One more question. How do I create a single char binary string from a
> number? E.g.
>
> >>> bytes([65])
> b'A'
>
>
bytes/str.ljust()
def pad(b, n=16, c=b"\x0f"):
... length = (len(b)+n-1)//n*n
... return b.ljust(length, c)
Thanks!
One more question. How do I create a single char binary string from a
number? E.g.
>>> bytes([65])
b'A'
It seems to be wrong again. The bytes constructor requires a
Nagy László Zsolt wrote:
> I can figure out way for example this:
>
> >>> b'T'+bytearray([32])
>
> but it just don't seem right to create a list, then convert it to a byte
> array and then convert it to a binary string. What am I missing?
By the way, you can repeat bytes (and strings) by multip
bytes/str.ljust()
def pad(b, n=16, c=b"\x0f"):
... length = (len(b)+n-1)//n*n
... return b.ljust(length, c)
Thanks!
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--
https://mail.python.org/mailman/listinfo/python-li
Nagy László Zsolt wrote:
> >>> BS = 16
> >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
> >>> pad('L')
> 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'
> >>> pad(b'L')
> Traceback (most recent call last):
>File "", line 1, in
>File "", line 1, in
Nagy László Zsolt wrote:
> >>> BS = 16
> >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
> >>> pad('L')
> 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'
> >>> pad(b'L')
> Traceback (most recent call last):
>File "", line 1, in
>File "", line 1, in