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


Groups > comp.lang.python > #99185

Re: String format - resolve placeholders names

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ervin Hegedüs <airween@gmail.com>
Newsgroups comp.lang.python
Subject Re: String format - resolve placeholders names
Date Fri, 20 Nov 2015 20:36:31 +0100
Lines 36
Message-ID <mailman.20.1448048195.2291.python-list@python.org> (permalink)
References <20151120145227.GB13994@arxnet.hu> <mailman.3.1448034840.2291.python-list@python.org> <n2nk25$mns$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de Ivu8nnZKmf4jm/oqvO8CEwncJA1dleqxar32t5Utz0YA==
Return-Path <airween@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'utf-8': 0.07; 'cc:addr :python-list': 0.09; 'python': 0.10; 'received:74.125.82.44': 0.15; '(key,': 0.16; 'keys:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 's))': 0.16; 'subject:String': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'all,': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'keys': 0.22; 'cc:no real name:2**0': 0.22; 'this:': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'fri,': 0.27; 'raise': 0.29; "i'm": 0.30; 'received:google.com': 0.35; 'nov': 0.35; 'received:74.125.82': 0.35; 'subject:: ': 0.37; 'thanks': 0.37; 'format': 0.39; 'more': 0.63; '20,': 0.66; 'satisfied': 0.83; 'denis': 0.84; 'otten': 0.84; ':).': 0.91; 'received:hu': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=4pV9bTvwlu44GDvJn3T35acEYIhmAR+YQZZB3uMKl6M=; b=GvAwxK1ArL493Qoj//OVgN4S6pjSXLcxKzB9DCmKhKbXDZ2dyUBLv49hBdoEn/MxLc Z2ymsIsqgEiHUnWhv6h44lTRCb+Bt4cNuac7BRQ5O9mE4eu/FS+/0WdAmMmKa8THS95r PWGU+suPNW/SQdnAanwt0IwNpaUAAN8+QbB6Uv7TfvEm725WMrkUZvJvb+5lYe7K6aBS GG7crtULhfY0khb/pwskuUQkwoVfQkoLSxd8C/1Ms25dVX1hSEHJseVlgEuK5FKImmos jhQIanaDjYtov4LdLM55rKbX+ccm9pOwT0IQrIQgKmiS8dDWJYDKLTym7OmqriPb0wNj mMZA==
X-Received by 10.194.243.6 with SMTP id wu6mr16166681wjc.14.1448048193362; Fri, 20 Nov 2015 11:36:33 -0800 (PST)
Content-Disposition inline
In-Reply-To <n2nk25$mns$1@dont-email.me>
User-Agent Mutt/1.5.21 (2010-09-15)
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>
Xref csiph.com comp.lang.python:99185

Show key headers only | View raw


Hi Denis,

On Fri, Nov 20, 2015 at 05:08:21PM -0000, Denis McMahon wrote:
> On Fri, 20 Nov 2015 16:53:47 +0100, Peter Otten wrote:
> 
> > Ervin Hegedüs wrote:
> 
> >> Python has a good string formatter, eg. I can do this:
> 
 
> Or even:
> 
> >>> s = "{who} likes {what}"
> >>> d = {'who': "Adam", 'what': "ants"}
> >>> keys = [x[1] for x in string.Formatter().parse(s)]
> >>> keys
> ['who', 'what']
> 
> then ...
> 
> for key in keys:
>     if key not in d:
>         raise KeyError("Missing key '{}' in format string '{}'".format
> (key, s))

well, I think I'm very satisfied - I got better and more better
solutions :).


Thanks for all, folks:

a.
 

-- 
I � UTF-8

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


Thread

Re: String format - resolve placeholders names Peter Otten <__peter__@web.de> - 2015-11-20 16:53 +0100
  Re: String format - resolve placeholders names Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-20 17:08 +0000
    Re: String format - resolve placeholders names Ervin Hegedüs <airween@gmail.com> - 2015-11-20 20:36 +0100

csiph-web