yet another recipe on string interpolation

Dave Benjamin dave.benjamin at gmail.com
Thu Nov 4 23:52:38 EST 2004


Michele Simionato wrote:
> language="Python"
> print interp("My favorite language is $language.")
> 
> Do you have any comments? Suggestions for improvements?

Well, for what it attempts to do, I'd say your solution is ideal. 
However, I think that Ka-Ping Yee's implementation was more full-featured:

http://lfw.org/python/Itpl20.py

Of course, this goes above and beyond the functionality of Template, so 
your code example is orthogonal to the reasons I'd prefer his solution.

He did the same sort of stack trick that you're doing, also. This code 
was the first that I'd ever seen do it, and this was before 
sys._getframe() was available.

Dave



More information about the Python-list mailing list