我在這裏和那裏經歷了很多類似的帖子,但是他們中沒有一個似乎解決了我的問題。我有一個搜索文件路徑的方法:python:'str'對象不可調用?
def getDumpFile(self):
self.saveDump()
dumpname = str(self.filename)+'-01.netxml'
filepath = os.path.join('/some/path/to/file',dumpname)
try:
if os.path.exists(os.path.join('/some/path/to/file',dumpname)):
logging.debug("Filepath "+str(filepath))
return filepath
else:
logging.debug("File Not Found")
return None
except OSError as e:
logging.debug("File not created: "+str(e))
return None
,並在主函數中我調用這個函數是這樣的:
xmlfile = wscanner.getDumpFile()
,當我執行上面的代碼,發現在getDumpFile()
正確的路徑的方法,但在服務器給出例外:
Unexpected exception in wireless.views.attackAP with type <type 'exceptions.TypeError'> and error 'str' object is not callable
我真的不知道爲什麼經過filepath
到xmlfile
變量(我相信以前從未啓動)可能導致錯誤,請幫助。謝謝。
編輯:它實際上是代碼xmlfile = wscanner.getDumpFile()
,發出錯誤,但我不知道爲什麼。註釋掉這行會擺脫錯誤,但我稍後需要此路徑。
請提供完整的追溯你的錯誤。你甚至沒有把我們指向錯誤發生的那一行。 – 2012-03-22 15:21:54
確實有人定義了一個叫做str的變量,它隱藏了內建函數嗎?來自其他語言,我幾次意外地做了這件事。 – 2012-03-22 15:22:33
我的猜測,但沒有看到更多的代碼,它只是一個猜測 - 你需要返回一個實際的文件引用對象,或一些其他具有方法的對象,而不是文件名。 – 2012-03-22 15:24:37