Reverse pystache

I have this script:

import pystache
template = 'Hi {{person}}!'
data = {'person': 'Mom'}
txt = pystache.render(template, data)
print txt

      

What gives:

Hi Mom!

      

Is there a way to do something like:

data = reverse_pystache(txt, template)

      

To return a dictionary:

>>> data
{'person': 'Mom'}

      

That is, by reusing the template that was used to generate the text and the actual text, extract the data from the text.

+3
python mustache


source to share


No one has answered this question yet

Check out similar questions:

1266
Reverse a string in Python
1085
Correct way to declare custom exceptions in modern Python?
994
How do I return multiple values ​​from a function?
930
How do I change a list in Python?
873
Big data workflows using pandas
471
How do I import a module by name as a string?
310
How do I find the script directory with Python?
274
Printing lists as tabular data
204
Run a python script from another python script by passing in args
188
What's the best practice using a settings file in Python?



All Articles
Loading...
X
Show
Funny
Dev
Pics