【发布时间】:2022-12-01 08:23:28
【问题描述】:
读取一个 android 显示模式监视器,它给出了插入分辨率的值。如果连续多次读取“null”,我希望循环中断:
Display Mode: 720p60hz
Display Mode: 720p60hz
Display Mode: null
Display Mode: null
Display Mode: null
Display Mode: null
BREAK!
CODE
import time
import subprocess
while True:
z = subprocess.getoutput("adb shell cat /sys/class/display/mode")
time.sleep(.1)
print(f'Display Mode: {z}')
t1 = time.time()
t2 = time.time()
if z == 'null':
print(f't1 is :{t1}')
else:
continue
if z == 'null'
print(f't2 is :{t2}')
print('i am null')
if t2-t1 > .1:
break
【问题讨论】:
-
您可以通过以下方式与“null”进行比较:
if z is None:。 -
@ewong OP 比较的输出是一个字符串
-
@BTables 感谢您的澄清。我的立场得到纠正。
标签: python loops while-loop