How do I parse a templated string in Python?

Posted by mLewisLogic on Stack Overflow See other posts from Stack Overflow or by mLewisLogic
Published on 2010-05-19T20:25:40Z Indexed on 2010/05/19 20:30 UTC
Read the original article Hit count: 181

Filed under:

I'm new to Python, so I'm not sure exactly what this operation is called, hence I'm having a hard time searching for information in it.

Basically I'd like to have a string such as:

"[[size]] widget that [[verb]] [[noun]]"

Where size, verb, and noun are each a list.

I'd like to interpret the string as a metalanguage, such that I can make lots of sentences out permutations from the lists. As a metalanguage, I'd also be able to make other strings that use those pre-defined lists to generate more permutations.

Are there any capabilities for variable substitution like this in Python? What term describes this operation if I should just Google it?

© Stack Overflow or respective owner

Related posts about python