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


Groups > comp.lang.python > #99155

String format - resolve placeholders names

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Ervin Hegedüs <airween@gmail.com>
Newsgroups comp.lang.python
Subject String format - resolve placeholders names
Date Fri, 20 Nov 2015 15:52:27 +0100
Lines 35
Message-ID <mailman.0.1448031143.2291.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
X-Trace news.uni-berlin.de 6PcrQXazgHb6fMnqYgDcNwWgTu2yRJ3iiw6DbcjdNk5g==
Return-Path <airween@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.040
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'method:': 0.09; 'python': 0.10; 'received:io': 0.16; 'received:psf.io': 0.16; 'result:': 0.16; 'subject:String': 0.16; 'string': 0.17; 'exists': 0.18; 'try:': 0.18; 'keyerror:': 0.22; 'this:': 0.23; 'thanks,': 0.24; 'header:User-Agent:1': 0.26; 'except': 0.34; 'received:google.com': 0.35; 'possible,': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr :python-list': 0.36; 'names': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; '(direct)': 0.84; 'received:86': 0.93; 'received:hu': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=BsyT4y9WrOGZDqRwwKojHLTKiDfXttppZOqOWJlrgJs=; b=t7oX9JkIhboECgpUOSNjW4N4QDat51DiaMl3Mc1eiw8jn1IcN8ycLzR3HDDKKUEEb2 Lq9GoNttLmHAKW9z7JwHXy212Verblolx5EDQDfLSvHd1q+tsOIAkltZffROwTVoDPq5 YiccOrCjH0jB70lIC1gwadsAzhRmvZESXtc8suVtJAdKdaytaDfWTE1zePvVSGuAoB7p HezKjpSVOsqtd4vbb1GjYYiJ3t2v/5Qivxj8qzdGG3OvuDeKxnboO7l22ZShpOGx99f2 31jUcBYMs+/NkJkStjRjTNKZIYropWhuC2nkkOvgjjgiNL7gCEwSwGCPhjVweFvKR3fQ wlwg==
X-Received by 10.28.145.134 with SMTP id t128mr352836wmd.64.1448031135683; Fri, 20 Nov 2015 06:52:15 -0800 (PST)
Content-Disposition inline
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:99155

Show key headers only | View raw


Hi,

Python has a good string formatter, eg. I can do this:

s = "{who} likes {what}"
d = {'who': "Adam", 'what': "ants"}
s.format(**d)

result:
'Adam likes ants'

Is it possible, and if yes, how to resolve the placeholders names
in string?

There is a know method:

d1 = {'who1': "Adam", 'what1': "ants"}
try:
    s.format(**d1)
except KeyError:
    print("keyword missing")

(gives 'keyword missing' as result).


But is there any other (direct) way, which keywords exists in
string?


Thanks,


a.

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


Thread

String format - resolve placeholders names Ervin Hegedüs <airween@gmail.com> - 2015-11-20 15:52 +0100

csiph-web