1

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?

2 Answers2

0
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.

M.Hefny
  • 2,677
  • 1
  • 26
  • 30
  • thanks for your quick response, unfortunately, when I do that the one import that does work in my code then fails as well ie I now get **ImportError: cannot import name data_cleaner** – Fogo Fortitude Aug 13 '17 at 03:37
  • My apologies, what you had stated was in fact correct...however my Class was named DataCleaner; when I use the following: `from process_data.data_cleaner import DataCleaner` it works. ...However, when I reference the other Class located in a seperate folder its this class ie `from audit_data.audit_file import AuditFile` . that fails and returns the error msg: **ImportError: No module named audit_data.audit_file** – Fogo Fortitude Aug 13 '17 at 03:53
0

The cause of my problem was a silly one; The folder containing the class I was calling was named audit _file whilst the folder I was calling within my code was audit_file

What didnt work from audit_data.audit_file import AuditFile

What worked from audit _data.audit_file import AuditFile

For those reading this watch out for unintended spaces in your folder names