[英]'function' object has no attribute 'today'
嘗試使用日期時間函數時出現此錯誤。 我正在使用空閑 Python 3.7。 日期時間函數曾經可以工作,但現在突然不行了。
updatedate = datetime.date.today()
AttributeError: 'function' object has no attribute 'today'
我嘗試使用“導入自”代碼來啟動更具體的導入,但它們無濟於事。 我也試過將 import datetime 放在 def constructor(): 中,但無濟於事。
import datetime
dictionary = dict()
def constructor():
updatedate = datetime.date.today()
dictionary['Update_Date'] = updatedate
print(dictionary)
updatedate = datetime.date.today()
AttributeError: 'function' object has no attribute 'today'
我希望 datetime.date.today() 函數將今天的日期保存為變量“updatedate”,然后輸入該日期作為字典“dictionary”中鍵 ['Update_Date'] 的值
在datetime
有另一個名為datetime
對象。 您必須使用 this 而不是date
。
例子:
import datetime
dictionary = dict()
def constructor():
updatedate = datetime.datetime.today()
dictionary['Update_Date'] = updatedate
print(dictionary)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.