Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'binary': 0.07; 'string': 0.09; 'bytes.': 0.09; 'constructor': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'def': 0.12; 'creates': 0.14; 'question.': 0.14; 'number?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'sequence,': 0.16; 'tuple': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'char': 0.24; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; "i'm": 0.30; 'thanks!': 0.32; 'subject: (': 0.35; 'subject:with': 0.35; 'convert': 0.35; 'similar': 0.36; 'wrong': 0.37; 'list': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'length': 0.61; 'more': 0.64; 'nagy': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: pad binary string with a given byte value (python 3) Date: Sat, 20 Sep 2014 14:37:22 +0200 Organization: None References: <541D5025.4070604@shopzeus.com> <541D715E.9000102@shopzeus.com> <541D7395.6030709@shopzeus.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p57bdabd5.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411216656 news.xs4all.nl 2848 [2001:888:2000:d::a6]:34174 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78105 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.