Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78104

Re: pad binary string with a given byte value (python 3)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gandalf@shopzeus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'string.': 0.05; 'binary': 0.07; 'string': 0.09; 'clean.': 0.09; 'constructor': 0.09; 'subject:string': 0.09; 'def': 0.12; 'question.': 0.14; 'mailscanner,': 0.16; 'number?': 0.16; 'sequence,': 0.16; 'tuple': 0.16; 'subject:python': 0.16; 'seems': 0.21; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'char': 0.24; 'header:In-Reply-To:1': 0.27; 'scanned': 0.29; 'thanks!': 0.32; 'subject: (': 0.35; 'subject:with': 0.35; 'convert': 0.35; 'believed': 0.36; 'wrong': 0.37; 'list': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'dangerous': 0.60; 'length': 0.61; 'viruses': 0.61; 'more': 0.64
Date Sat, 20 Sep 2014 14:31:17 +0200
From Nagy László Zsolt <gandalf@shopzeus.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: pad binary string with a given byte value (python 3)
References <541D5025.4070604@shopzeus.com> <lvjqin$4ln$1@ger.gmane.org> <541D715E.9000102@shopzeus.com>
In-Reply-To <541D715E.9000102@shopzeus.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-shopzeus-MailScanner-Information Please contact the ISP for more information
X-shopzeus-MailScanner-ID E4AD68897398.AB666
X-shopzeus-MailScanner Found to be clean
X-shopzeus-MailScanner-From gandalf@shopzeus.com
X-Spam-Status No
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14167.1411216285.18130.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411216285 news.xs4all.nl 2859 [2001:888:2000:d::a6]:57789
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78104

Show key headers only | View raw


>> 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.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: pad binary string with a given byte value (python 3) Nagy László Zsolt <gandalf@shopzeus.com> - 2014-09-20 14:31 +0200

csiph-web