5 ms·
import * is the devil, really don't use it. Instead, hack up this recipe: http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-
by DrJosiah 16y ago
import * is the devil, really don't use it. Instead, hack up this recipe: http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-time/ http://code.activestate.com/recipes/277940-decorator-for-bin... to inject the common tags into the local namespace of the function. It will have the side-effect of making the code execute faster.
As for the callable variant, there are a few versions of that (nevow.stan was the first one in the style, I wrote a version a few years ago that I referenced in another post here, and I've seen a few pop up since) While it does work, indentation can get funky, looping gets tricky (you end up looping quite a bit with data-driven templates, it turns out), and closing parens aren't nearly as useful as a dedent. Being able to mix both styles may be a win.
- ljlolel 16y agoGreat comment! Agreed. I'm a little afraid of that hack though and what it might do to a query optimizer. You're right that the callable system makes loops tricky. Also, great point about the closing parens. We use python specifically to avoid them and to just use whitespace! In practice, I have done a mixed approach as you suggested. I used this iterative style with limited callable style embedded where that makes sense (everything just returns a string, so they embed cleanly).
- anthonyb 16y agoJesus, that's nasty. Hacking python bytecode is far, far worse than import *. I'd be more inclined to just use __all__ in your module to hide the bits that you don't want.