I am using python 3.3
I have a folder model with several modules, each with one class defined in it. The class has the same name as the module.
Now I want it so that when in the main script I do foo=Foo() that automatically the class module model.Foo is loaded with the effect of from model.Foo import Foo
How?
2 Answers 2
It is usually not a good idea to have automatic import. How would the python interpreter know that Foo is model.Foo ?
One way to "ease" importing classes is to load them in the module __init__.py
Ex: https://github.com/masom/shopify-trois/blob/master/shopify_trois/models
Someone else asked a similar question: Python Auto Importing
Comments
While agreeing with Martin's warning about doing so, if you really want to dynamically import code, have a look at the imp module.