tags:

views:

58

answers:

3

Ok yes it is a very silly question, but just that I am getting a little confused. I have a file structure which looks like this:-

-Mainapplication
   -models.py
-Helpingmodules
   -Folder1
     -module1.py

Now I have to import models into module1. So in module1.py I just did:-

from Mainapplication import models 

Now this does work fine, but I get a feeling that it might be wrong. Can someone please let me know if this is the correct way.

+2  A: 

There's nothing wrong with the import, but if the names of your packages are accurate, this looks like a design flaw in that you're destroying code reusability; I'd expect a package of "helping modules" to be independent of the application they're helping (although in the case the package name is so vague that I could be way off about their purpose.)

Wooble
Thanks Woobie, yes the names of the packages are not correct.But yes the concept of reusability pointed me to something here..
Alice
A: 

Please check the below useful link :

http://docs.python.org/tutorial/modules.html

Memo Mazaz
+1  A: 

There's nothing wrong with your import.

You could say:

import Mainapplication.models

but then you'd have to reference models with its Package prefix every time you used it, e.g.:

Mainapplication.models.foo("bar")

The way you've done it allows you to use the following form which is usually preferable:

models.foo("bar")

For the full story you can read the documentation.

Dave Webb
Thanks Dave, one up!
Alice