0

Hello I want to import a class from another class.

My file structure is the following:

Project
│
├─ folder1/
│   └─ file1.py
│
└─ folder2
     └─ file2.py

file1.py

from folder2.file2 import B

class A:
  """some things"""

file2.py

from folder1.file1 import A

class B:
  """something"""

class C(A):
   """something"""

When I run file1.py It says:

File "./folder1/file1.py", line 1, in from folder2.file2 import B

File "./folder2/models.py", line 1, in from folder1.models import A

ImportError: cannot import name A

Ivan
  • 34,531
  • 8
  • 55
  • 100
IronCoder
  • 11
  • 1
  • if you need it for models FK you can use string `app.ModelName` other case read https://stackoverflow.com/questions/17226016/simple-cross-import-in-python – Brown Bear Jun 23 '18 at 08:11
  • @BearBrown I did't knew this condition was called Cross import. So, I could not search this solution. – IronCoder Jun 23 '18 at 08:43

0 Answers0