我不知道我在下面的代碼行中做錯了什么,這讓我抓狂!正如您可能從代碼中了解到的那樣,我只希望if 塊在下午 5 點 15 分之前運行。
if time(datetime.now().hour,datetime.now().minute) < time(17, 15):
我已經匯入date
,datetime
所以這不是問題(這是TypeError
錯誤 - 請參閱下面我收到的錯誤訊息)
Exception has occurred: TypeError (note: full exception trace is shown but execution is paused at: _run_module_as_main) 'module' object is not callable
有人可以建議我做錯了什么
uj5u.com熱心網友回復:
短一點:
from datetime import datetime, time
datetime.now().time() < time(20,10) # False
uj5u.com熱心網友回復:
你可能想要from datetime import time
:
from datetime import datetime, time
now = datetime.now()
if time(now.hour, now.minute) < time(20, 15):
print("Hello")
列印(現在):
Hello
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/535623.html
標籤:Pythonpython-3.x约会时间if语句python-日期时间
上一篇:無法無條件呼叫方法“[]”,因為接收者可以為“null”。嘗試使呼叫有條件(使用“?”)
下一篇:flutter中呼叫API報錯_InternalLinkedHashMap<String,dynamic>如何解決?