I would like to get a list of all possible keyword arguments that the string template can use in the wildcard.
Is there any way to do this otherwise than re?
I want to do something like this:
text="$one is a $lonely $number." keys = get_keys(text) # keys = ('one', 'lonely', 'number')
I am writing a simple Mad-lib-like program, and I want to replace the template with string.format or Template strings . I would like to write a โstoryโ, and my program will create a template file of all the โkeywordsโ (nouns, verbs, etc.) that the user will have to create. I know I can do this with regular expressions, but I was wondering if there is an alternative solution? I am open to alternatives to the template string.format and string.
I thought it would be a solution, but I did not find it in search of a quick search. I found this question, the reverse pattern with python , but that is not quite what I am looking for. It simply confirms that this can be done with re .
EDIT:
I should notice that $$ is an escape for '$' and is not the token I want. $$5 should display the value "$ 5".
python string-formatting
Yann
source share