0

So firstly, I use the first file to import the second using import second_file then in the second file, I import the first file with the same way and it works and I also import the third file from the first file BUT when I try to import the first file from the third it doesn't work

So: file1 ----> import second_file file 2 ----> import first_file file1 ----> import third_file file 3 ----> import first_file THAT IMPORT DOESN'T WORK

  • 1
    This is an example of a cyclic import, where two (or in this case three) modules import each other. There are ways to deal with these in python, but it depends on the situation. In general they should be avoided and in the vast majority of cases its possible to restructure the code in such a way the cyclic import is avoided entirely. – Aaron de Windt Apr 23 '20 at 10:42
  • I found a temp solution using runpy and runpy.run_module(mod_name="") – Thanasis Mitragkas Apr 23 '20 at 11:38

1 Answers1

0

You can try the following

from first_file import *
from Second_file import *
Kalyan Mohanty
  • 95
  • 1
  • 10