Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python files - import from each other

I would like for two of my python files to import some methods from each other. This seems to be giving me import errors.

Example:

file_A.py:

from file_B import do_B_stuff

file_B.py:

from file_A import do_A_stuff

The reason I am trying to do this is because I would like to organize my project in the way it intuitively makes sense to me as opposed to organizing it with respect to what makes sense to the compiler.

Is there a way to do this?

Thanks!

like image 871
Chris Dutrow Avatar asked Mar 09 '12 23:03

Chris Dutrow


1 Answers

Don't use the names within the other module directly.

file_A.py

import file_B

def something():
    file_B.do_B_stuff

file_B.py

import file_A

def something():
    file_A.do_A_stuff
like image 149
Ignacio Vazquez-Abrams Avatar answered Oct 06 '22 01:10

Ignacio Vazquez-Abrams