On Tue, Jul 27, 2010 at 7:17 PM, Bruce Frederiksen <span dir="ltr"><<a href="mailto:dangyogi@gmail.com" target="_blank">dangyogi@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
The one catch is that it is often nice to be able to refer to Python variables (at least; or perhaps full expressions) within the mini-language. The db_cursor.execute is an example, and putting the placeholders in the SQL syntax with arguments later works, but gets tedious. To be able to include Python expressions directly within the mini-language, the library implementing the new syntax would have to be able to translate the new syntax into Python and have it spliced into the code where it was used. Something like an intelligent macro expansion. This means that the library's translation code has to be called from the Python compiler.<br>
<br>I'm not familiar enough with the compiler to know how crazy this is. Mython tries to do something similar.<font color="#888888"><br></font></blockquote><div><br>Basically templating languages do this, and a templating language could be used for exactly this sort of purpose (but *not* simply a generic templating language, then you get SQL or whatever-else injection problems).<br>
<br>I put together a small example that might work for SQL: <a href="http://svn.colorstudy.com/home/ianb/recipes/sqltemplate.py">http://svn.colorstudy.com/home/ianb/recipes/sqltemplate.py</a><br><br clear="all">Unfortunately templating languages in Python aren't nearly as easy to implement as they should be, and the results are not as elegant as they could be. I've been using templating snippets a lot more in my code lately, and find it more handy than I would have originally expected. It doesn't seem unreasonable in this case either. Well... unless you want to introspect the expression, which would mean parsing the resulting SQL (and is then hard).<br>
</div></div><br>-- <br>Ian Bicking | <a href="http://blog.ianbicking.org" target="_blank">http://blog.ianbicking.org</a><br>