我在Windows 7 Professional上使用Python 2.7。來自其他文件的Python調用函數
我想調用保存在另一個文件中的函數來運行'這個文件'的代碼。
功能稱爲dosomething
在anotherfile.py
發現「anotherfile.py`是在相同的目錄中的電流的代碼。
我的電話很簡單:
import anotherfile
print anotherfile.dosomething
我得到一個錯誤:No module named anotherfile
的問題是相同的,因爲我在this post
我不明白的解決方案中。
Insight?
謝謝。
編輯:其他問題/答案討論重置CLASSPATH和設置PYTHONPATH。我探討了這一點,但不知道如何做到這一點。也許有關?
'anotherfile.dosomething()'因爲它是一個函數 – depperm
當我這樣做時,我得到'NameError:name'另一個文件'沒有定義' – Windstorm1981