Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78105
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: pad binary string with a given byte value (python 3) |
| Date | 2014-09-20 14:37 +0200 |
| Organization | None |
| References | <541D5025.4070604@shopzeus.com> <lvjqin$4ln$1@ger.gmane.org> <541D715E.9000102@shopzeus.com> <541D7395.6030709@shopzeus.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14168.1411216656.18130.python-list@python.org> (permalink) |
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' > > It seems to be wrong again. The bytes constructor requires a sequence, > and I don't like creating a list or a tuple just to convert it into a > binary string. Unfortunately I'm not aware of a function similar to chr() that creates bytes.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: pad binary string with a given byte value (python 3) Peter Otten <__peter__@web.de> - 2014-09-20 14:37 +0200
csiph-web