我在这里遇到了类似的主题,并通过了文档,但仍然遇到以下代码块的问题:
var distanceToPump = 50;
var mpg = 25;
var fuelLeft = 2;
var zeroFuel = (distanceToPump, mpg, fuelLeft) => { return ( mpg * fuelLeft )
== distanceToPump ? true : false; }
console.log(zeroFuel())
该函数返回false,而三元运算符返回true。哪里出错了? UPD。我的问题是这种差异来自哪里,函数zeroFuel中的错误在哪里?
答案 0 :(得分:1)
当你致电undefined
时,你没有传递任何论据。
因此,定义为参数的局部变量得到值(undefined * undefined) == undefined
。
import time
from datetime import datetime
import sys
from struct import unpack
from RF24 import RF24
import psycopg2
irq_gpio_pin = None
con = None
radio = RF24(22, 0)
def get_data_from_node():
if radio.available():
while radio.available():
length = 10
receive_payload = radio.read(length)
values = unpack('hhhhh',receive_payload)
print "Node Number: "+str(values[0])+"\nLight: "+str(values[1])+" Humidity: "+str(values[2])+" Temperature: "+str(values[3])+" MQ6: "+str(values[4])
#TIMESTAMPT = "(%s)",(datetime.now(),)
LOG="INSERT INTO LOGS (HUMIDITY,TEMPERATURE,PRESSURE,AIR_QUALITY,READING_TIME,LOG_TIME,BASE_STATION_ID) VALUES("+str(values[1])+","+str(values[2])+","+str(values[3])+","+str(values[4])+",('%s'),('%s'),1);" % (datetime.now(),datetime.now(),)
write_to_db(LOG)
def write_to_db(LOG):
try:
con = psycopg2.connect(database='dname', user='uname', password='pass')
con.cursor().execute(LOG)
con.commit()
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
pipes = ["0Node", "1Node"]
radio.begin()
radio.setRetries(15,15)
radio.printDetails()
radio.openWritingPipe(pipes[1])
radio.openReadingPipe(1,pipes[0])
radio.startListening()
while 1:
get_data_from_node()
time.sleep(0.1)
是假的。
从不使用更广范围内具有相同名称的变量。
答案 1 :(得分:-1)
刚刚在控制台中测试,zeroFuel(distanceToPump, mpg, fuelLeft)
返回true。