Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99155 > unrolled thread
| Started by | Ervin Hegedüs <airween@gmail.com> |
|---|---|
| First post | 2015-11-20 15:52 +0100 |
| Last post | 2015-11-20 15:52 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
String format - resolve placeholders names Ervin Hegedüs <airween@gmail.com> - 2015-11-20 15:52 +0100
| From | Ervin Hegedüs <airween@gmail.com> |
|---|---|
| Date | 2015-11-20 15:52 +0100 |
| Subject | String 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.
Back to top | Article view | comp.lang.python
csiph-web