[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: importing modules from subdirs

Gary Herron

3/11/2010 6:00:00 PM

Alex Hall wrote:
> Hi all,
> The manual says, for modules in a project stored in subdirectories, you can do:
> import folderName.module
>
> I have a couple questions, though:
> 1. Do I then have to call functions from module like
> folder.module.function, or can I still use the normal module.function?
>

Either, depending on how you do the import:

import folder.module
folder.module.function()

or

from folder.module import function
function()

or

from folder import module
module.function()

> 2. When I try to do this, it fails. I have an sw folder. Inside that I
> have a modes folder, holding weather.pyw. Main.pyw, back in the sw
> folder, is trying to import modes.weather, but nothing happens. I have
> tried putting weather.pyw in its own weather folder under the modes
> folder, but that also fails. I have placed an empty __init__.py file
> in both the modes folder and the weather subfolder, but I cannot get
> main.pyw to import weather!
>

Show us some code and a diagram of your forcer hierarchy, and we'll look
at it.
> 3. How does weather import from a folder above or beside it? For
> example, if a config directory is at the same level as the modes
> directory, how can weather import something from config?
>

You don't import from up the hierarchy. You can put a higher folder on
sys.path, and get to it that way.

Gary Herron


> Thanks!
>
>