extract a dictionary from a string with keys in brace brackets

Is there a way in python to extract a dictionary from a string which includes brace brackets, having the keys of the dictionary referencing the words in the brace brackets?

as an example:

'my name is {name}'

the method would return the following dictionary:

{'name':{}}

This would be to later use the dictionary and populate the string through parameters using .format()

'my name is {name}'.format(**{'name':'salomon'})

The all objective is to read a text file, put brace brackets around words I'd like to transform in parameters, load the text file and extract a dictionary where I can input the desired values to then reinject in the text.

Thank you,



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Spring Boot and Vaadin : Filtering rows in Vaadin Grid