0

I have three classes having to import each others methods. The statements would be as follows in the corresponding files with classes:

File A with class a

from B import b

File B with class b

from C import c

File C with class c

from A import a

Why does this not work in python? I rather get the error message:

ImportError: cannot import name a  
Ingo
  • 1,732
  • 10
  • 26
  • 34
  • 4
    Circular imports, apart from being able to bite you badly, are also rarely (if ever) necessary and usually show design flaws. Try to avoid them. As for import problems ingeneral, the contents of those files and the actual filenames (usually) matter. –  Nov 03 '10 at 19:01
  • possible duplicate of [Circular import dependency in Python](http://stackoverflow.com/questions/1556387/circular-import-dependency-in-python) – SilentGhost Nov 03 '10 at 19:02
  • Thanks for noting that, I was not familiar with the terminology circular import. – Ingo Nov 03 '10 at 19:05

2 Answers2

2

What you have is a classic circular import problem in Python. Have you taken a look at previous questions on SO, like this one?

Community
  • 1
  • 1
Santa
  • 11,381
  • 8
  • 51
  • 64
0

Python can't find it. Is it in the proper directory, does it actually exist?

user489041
  • 27,916
  • 55
  • 135
  • 204