Python files - import from each other

橙三吉。 提交于 2019-11-26 20:36:31

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/9642451/python-files-import-from-each-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!