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


Groups > comp.lang.python > #96453

string_formatter 1.0.1 released

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <anthon@mnt.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:skip:s 10': 0.05; 'strings.': 0.07; 'subject:released': 0.07; 'parameter.': 0.09; 'bug': 0.10; 'python': 0.10; '(at': 0.13; "'a',": 0.16; 'keys.': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:eu': 0.16; 'string': 0.17; 'nested': 0.18; '>>>': 0.20; 'class,': 0.22; 'keys': 0.22; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'least': 0.27; 'key,': 0.29; 'received:78.46': 0.29; 'character': 0.29; 'allows': 0.30; '15,': 0.30; 'skip:s 30': 0.31; 'to:addr:python-list': 0.36; 'received:org': 0.37; 'skip:p 20': 0.38; 'format': 0.39; 'to:addr:python.org': 0.40; 'received:194': 0.61; '(that': 0.63; 'applying': 0.70
Date Fri, 11 Sep 2015 22:51:22 +0200
From Anthon van der Neut <anthon@mnt.org>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0
MIME-Version 1.0
To python-list@python.org
Subject string_formatter 1.0.1 released
References <CAFrp1vp4KSmH3-O4ewU3DwkrrZ+WUO6J-aExWc2GoppSSs_oEQ@mail.gmail.com>
In-Reply-To <CAFrp1vp4KSmH3-O4ewU3DwkrrZ+WUO6J-aExWc2GoppSSs_oEQ@mail.gmail.com>
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Sat, 12 Sep 2015 22:02:41 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.444.1442088163.8327.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442088163 news.xs4all.nl 23837 [2001:888:2000:d::a6]:35428
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96453

Show key headers only | View raw


string_formatter is a backport of the 3.4.1+ string.Formatter class, to
2.7, 3.3 and 3.4.0. This allows the use of empty keys {} in its format
strings.

At the same time it solves an existing (at least until 3.5.0.rc3) bug in
string.Formatter, breaking with the use of nested empty keys.
Python 3.4.3:

    >>> import string
    >>> string.Formatter().format("|{:<{}} {}|", 'a', 3, 5)
    '|a   3|'


In addition (that is how it all started) it provides TrailingFormatter
which allows a type specification "t" with a single character parameter.
That character will be added to the (stringified) value before applying
(left-aligned) formatting:

    import string_formatter as string

    fmt = string.TrailingFormatter()
    d = dict(a=1, bc=2, xyz=18)
    for key in sorted(d):
        print(fmt.format("{:t{}<{}} {:>3}", key, ':', 15, d[key]))

giving:

    a:                1
    bc:               2
    xyz:             18

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


Thread

string_formatter 1.0.1 released Anthon van der Neut <anthon@mnt.org> - 2015-09-11 22:51 +0200

csiph-web