On Tue, May 12, 2009 at 12:12 PM, Dalius Dobravolskas <[email protected]> wrote: > > mk wrote: >> Hello everyone, >> >> I'm trying to do 'modular importing' in helpers.py, rationale being I >> don't want to cram it all into helpers.py; several modules and/or >> developers might want to do things completely independently of each >> other. My idea was smth like that: >> >> hello_helpers.py: >> >> def import_function(): >> from routes import url_for >> >> >> in helpers.py: >> >> from hello_helpers import import_function >> import_function() >> >> But. That doesn't work. >> > It shouldn't. "import" inside function will import only into that > function scope. I think you should use different files and import them. > Maybe it is possible to do the same with decorators but I'm not sure > about that.
You would have to use a namespace trick to inject the variables into the calling scope. I'm not sure exactly how, but it's unpythonic anyway. You don't have to use helpers.py, you can simply import the desired modules directly into the controller or template requiring them. And you can write a custom version of pylons.templating.render_mako() that implicitly adds them to the template namespace. -- Mike Orr <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
