我是python新手,所以這可能是我剛纔錯過的東西... 我只是想運行一個文件,調用另一個文件。python typeerror'module'object is not callable
我有一個像myfile.py文件:
#!/usr/bin/python
import another_file
things = ... """ some code """
def mystuff(text, th=things):
return another_def(text, th)
「another_file
」可以編譯/自身運行良好,並具有高清「another_def
」和變量「th
」(這些只是示例名稱。 ..)
所以我在命令行中運行python
,然後嘗試:
>>> import myfile
>>> t = myfile.mystuff('some text')
,我得到的錯誤:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "myfile.py", line 18, in mystuff
return another_def(text, th)
TypeError: 'module' object is not callable
我試圖import another_file
即使是在myfile.py
但似乎沒有任何區別。
如果這有什麼差別,我想:
print myfile
<module 'myfile' from 'myfile.py'>
print myfile.mystuff
<function mystuff at 0x7fcf178d0320>
,所以我認爲,如果能找到的文件和功能,問題是它試圖如何調用其他文件....也許。任何幫助感謝!
你能發佈方法代碼'myfile.mystuff'這似乎是有問題? –
如果您更改了名稱以保護無辜者,您已經很難回答這個問題。 「模塊不可調用」錯誤意味着您正在嘗試使用模塊,就像它是一個函數一樣。 – doctorlove
@doctorlove我改變了名字,希望讓問題看起來更容易(沒有效果,但是哦) - 實際上你是對的,因爲在原始代碼中,'another_file'和'another_def'具有相同的名稱。感嘆。感謝 – dgBP