我得到一個TypeError: object of type file' has no len()
我已經追溯到執行時建立的路徑的問題。用戶創建的日誌文件
我錯過了什麼,以糾正「savePath」減速或「temp = os.path.join(savePath,files)」內的使用內發現的錯誤?
def printTime(time):
savePath = "C:\Users\Nicholas\Documents"
files = open("LogInLog.txt", "a")
temp = os.path.join(savePath, files)
files.write("A LogIn occured.")
files.write(time)
print files.read
files.close
main()
整個程序如下供參考:
from time import strftime
import os.path
def main():
getTime()
def getTime():
time = strftime("%Y-%m-%d %I:%M:%S")
printTime(time)
def printTime(time):
savePath = "C:\Users\Nicholas\Documents"
files = open("LogInLog.txt", "a")
temp = os.path.join(savePath, files)
files.write("A LogIn occured.")
files.write(time)
print files.read
files.close
main()
你應該參考https://docs.python.org/2/library/logging.html – pigletfly
不是一個問題「事情是內'printTime()'函數走錯了」,至少說_what_出錯了。 – Julien
對不起編輯我的問題......認爲它是自我解釋性的,我正在嘗試做...但我沒有使用「import os.path」導入太多,並且無法嘗試將文件保存在代碼 –