0

May I have no searched thoroughly enough, please link me to it.

I am trying to import a function from another module. That modules also import some functions that the module.

Here's the folder system:

/foo/
    __init__.py
    foo.py
    bar.py

foo.py

from .bar import _function

bar.py

from .foo import some_other_function

which results in

ImportError : cannot import name 'some_other_function'

when a script in foo.py is ran.

Extra info :

__init__.py

from foo import w_function, y_function
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

1 Answers1

0

This problem is related to Cyclic imports. You can do -

from bar import *

and

from foo import *

Not sure whether this is advisable or not.

Also, in your case you can put your import statements inside the functions where the imports are actually required.

Your problem has a discussion and solutions here - Circular (or cyclic) imports in Python

Shashank
  • 584
  • 5
  • 16