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


Groups > comp.lang.python > #99155 > unrolled thread

String format - resolve placeholders names

Started byErvin Hegedüs <airween@gmail.com>
First post2015-11-20 15:52 +0100
Last post2015-11-20 15:52 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#99155 — String format - resolve placeholders names

FromErvin Hegedüs <airween@gmail.com>
Date2015-11-20 15:52 +0100
SubjectString format - resolve placeholders names
Message-ID<mailman.0.1448031143.2291.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web