0

My file structure is:

Project/
--classes.py
--display.py
--logic.py
--main.py
--settings.py

main.py imports

from display import display_student_list
from logic import register, welcome, stud_search

display.py imports

from logic import display_json 
from settings import WORKDIR

settings.py imports

import os

and then

logic.py imports

from display import display_search
from classes import student
from settings import WORKDIR

The problem I'm having is when I import from display import display_search in logic.py it throws me an ImportError cannot import 'display_search',

but when I remove it, all works fine. It works also when I import it from another place like main.py

Is it wrong to import from file_a to file_b and file_b to file_a I tried changing both to "from display import *", "from logic import *" and it works, why does importing a function name won't work?

martineau
  • 119,623
  • 25
  • 170
  • 301
skylar
  • 33
  • 1
  • 5
  • Are you sure `display.py` has a function called `display_search`? – M-Chen-3 Feb 03 '21 at 00:01
  • You can't have circular imports, since it will recurse infinitely. – Barmar Feb 03 '21 at 00:04
  • Yes, I am sure. I even tried importing display_search from another file, it works on main.py but also won't work on settings.py – skylar Feb 03 '21 at 00:05
  • @Barmar oh yeah, that makes sense. Thank you! I didn't realized it lol, but why does "from file import *" works but not "from file import function" i'm now just curious. – skylar Feb 03 '21 at 00:07

0 Answers0