检查时间是否在今晚和明天早上之间

Oss*_*ama 4 python time if-statement

以下条件不起作用,任何想法?Python认为8am属于同一天,所以这种情况不可能吗?

from datetime import datetime, time
now = datetime.now()
now_time = now.time()
if now_time >= time(23,00) and now_time <= time(8,00): 
    try:
        print 'hall light turning on'
    except:
        print 'Could not connect to Hue gateway'
Run Code Online (Sandbox Code Playgroud)

Mar*_*som 13

小时如何同时> = 23且<= 8?

尝试替换andor:

if now_time >= time(23,00) or now_time <= time(8,00):
    print "night"
Run Code Online (Sandbox Code Playgroud)