本文介紹了Python 文件 - 相互導(dǎo)入的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想讓我的兩個(gè) python 文件相互導(dǎo)入一些方法.這似乎給了我導(dǎo)入錯(cuò)誤.
I would like for two of my python files to import some methods from each other. This seems to be giving me import errors.
示例:
file_A.py:
from file_B import do_B_stuff
file_B.py:
from file_A import do_A_stuff
我之所以嘗試這樣做是因?yàn)槲蚁胍詫ξ襾碚f直觀的方式來組織我的項(xiàng)目,而不是按照對編譯器有意義的方式來組織它.
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.
有沒有辦法做到這一點(diǎn)?
Is there a way to do this?
謝謝!
推薦答案
不要直接使用其他模塊中的名稱.
Don't use the names within the other module directly.
import file_B
def something():
file_B.do_B_stuff
file_B.py
import file_A
def something():
file_A.do_A_stuff
這篇關(guān)于Python 文件 - 相互導(dǎo)入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!