Search code examples
python-2.7python-importpython-packagingmodule-packaging

How to import multiple class objects from seperate folders?


I built a python 2.7 application with the below directory structure for my relevant files. How do cal methods located in different folder locations?

Data-Wrangling-OpenStreetMap-data
 |
 +---- process_data
 |       |
 |       +---- __init__.py
 |       |
 |       +---- data_cleaner.py
 |
 +---- main_code.py
 |
 +---- audit _data
 |       |
 |       +---- __init__.py
 |       |
 |       +---- audit_file.py

I have succeeded in doing it correctly for one class referenced from main_code.py via the use of:

from process_data.data_cleaner import DataCleaner

However, if attempt a similar pattern for another class located in seperate folder referenced by main_code.py for via the use of the import statement

from audit_data.audit_file import AuditFile

I get the error:

ImportError: No module named audit_data.audit_file

Any ideas as to what I may be overlooking and/or guidance on what further details I need to post to help find the solution to my problem?


Solution

  • from process_data.data_cleaner import data_cleaner
    

    as data_cleaner is the file name data_cleaner.py and the second one data_cleaner is a class defined in it.