Importing Classes from child folders.

monosij.forums at monosij.forums at
Thu Jan 17 08:37:26 CET 2013

Trying to do some OO Python with files in different directories.
I have a blank in each directory.
It is my assumption that having an marks the directory as a module.
I am trying to run from the command line.

I would assume this has already been solved but could not find in forum
I am somewhat new to Python. Using Python3 under Ubuntu.
So I have a project structure as follows:
ProjectX (root folder)
+ service (folder under ProjectX) (has a class SystemSetup)
+ model (folder under ProjectX) (has a class Directory)

In if I want to use SystemSetup class, I do:
from service.SystemSetup import SystemSetup
and in Controller Class I have:
def main():
    systemSetup = SystemSetup()

I get error:
  File "", line 4, in <module>
  from service.SystemSetup import SystemSetup
ImportError: cannot import name SystemSetup

What am I doing wrong? I am running from the command line.
Do I need to set the project in PYTHONPATH first?

But if SystemSetup and Directory are in same directory as Controller I have no problems.

Your help would be highly appreciated.
Btw I also tried:
import sys, os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from service.SystemSetup import SystemSetup
No luck.

Thank you again.


More information about the Python-list mailing list