On Tuesday 11 August 2009 10:54:04 [email protected] wrote:
> I have a controller called "foo" in a file that is imported into my
> controllers.py.
>
> Foo needs access to a function "bar" defined in controllers.py.  The
> function is not part of any class, it just stands by itself.
>
> How can I get to "bar" from "foo".
>
> I imagine it's something like:
>
> import __main__
> __main__.controllers.foo()
>
> But that doesn't work...still something like that must be correct.

It would be 

  from myproject.controllers import foo


But you shouldn't do that, instead do it the other way round - place foo in 
some utility-module, and import that from the controller-module.

The reason is that importing from controllers might not work until TG is fully 
bootstrapped, and depending on the order of imports that's not guaranteeable. 
So as a rule of thumb: *never* import from a controller module.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to