【发布时间】:2020-04-30 20:59:01
【问题描述】:
我尝试在 python 3.7 中使用以下代码从各种传感器获取数据,然后将它们远程存储在 NAS 上的 MySQL 数据库中。
dataset = []
try:
while count<max:
humidite, temp = Adafruit_DHT.read_retry(sensor, pin)
time.sleep(2)
if humidite is not None and temp is not None:
print("avant ", dataset)
#print("La temperature est de : {0:0.1f}*C Humidité de : {1:0.1f}%".format(temp, humidite))
dataset = dataset.append((time.ctime(),'lieu',temp,humidite))
print("apres ", dataset)
count+=1
else:
print("Lecture des informations impossible")
except KeyboardInterrupt:
print("End of work")
dbase = get_connect()
add_data(dataset)
dbase.close()
我添加了一些打印来查看“数据集”。循环在第二遍失败(count=1),第一遍的数据集结果是:
avant []
apres None
.append 方法有问题吗?
【问题讨论】:
-
append修改现有列表并返回None。
标签: python list append attributeerror nonetype