1

I am currently learning how to work packages with Python but there still on thing I cannot understand.

My application is broken down like this (I made sure to add a __init __.py file in every single directory)

Home Directory

____sub folder1

____sub folder2

____sub folder3

When I try to access scripts top down or within the same directory it works great. However, when I try to call a script in the sub folder2 through the sub folder1, I get the following error:

from sub_folder1 import blablabla

ImportError: No module named blablabla

What I am missing here?

2 Answers2

1
from ..sub_folder1 import blablabla

should work when you are in sub_folder2

Daniel Kreiseder
  • 12,135
  • 9
  • 38
  • 59
0

If you will create a new project in django e.g. testDjango16 and 2 apps inside it lets say utility and core it will have the below structure as shown.

enter image description here

Then you can refer any app inside other as

from testDjango16.utility import models

in lets say core app, in this way everything will work.

for creating a new project django-admin.py startprojct testDjango16 and to create a new app you should use djang-admin.py startapp core or python manage.py startapp core

Mrityunjay Singh
  • 477
  • 5
  • 11