I have a string using the %
style formatting that I would like to extract its keys from:
s = 'Hello %(name)s, you are %(age)d years old!'
I would like to do something such as:
from string import Formatter
keys = {key for _, k, _, _ in Formatter().parse(s)}
print(keys)
# ('name', 'age')
However, this is unsupported with %
style formatting; is there another way? I've also already read: