Organizing Code - Packages

David wizzardx at gmail.com
Sat Sep 8 16:28:03 EDT 2007


>
> How do import statements that are declared at the top of a python
> module work?
>
> for instance....
>
> from MyModule.Objects import *
>
> class Class:
>       def function:
>            #here i cannot access the things that should have been
> imported from the above statement
>            #i printed the dir() function to verify this

I have seen this myself (stuff seemingly not imported) when 2 modules
import each other, perhaps indirectly, and try to use elements from
each other (at the global/declaration step, rather than in functions.
Logic that runs later (not during the import phase) still works fine,
however)). This sounds like the problem you're having, but your code
snippet isn't complete enough for me to tell. The way to fix this is
generally to move out stuff used by both modules into a separate
module.

Another reason can be that the imported module should be but isn't
setting the "__all__" variable. (in general the "import *" syntax is
frowned upon, it reduces readability).



More information about the Python-list mailing list