我是使用python的初学者。我正在展示我正在处理的代码的一部分。我试图使用elasticdump --input=http://localhost:9200/$SRC_IND --output=http://$TARGET_IP:9200/$TGT_IND --type=analyzer
elasticdump --input=http://localhost:9200/$SRC_IND --output=http://$TARGET_IP:9200/$TGT_IND --type=mapping
elasticdump --input=http://localhost:9200/$SRC_IND --output=http://$TARGET_IP:9200/$TGT_IND --type=data --transform "delete doc.__source['_id']"
和闪烁LED将python传递给arduino。我想使用函数pyserial
返回的值作为函数send_data
的输入。但是当我运行代码时,我收到了错误
未定义全局名称数据。
有任何建议要摆脱这个吗?
delay_for_goodant
我将这些函数称为代码的后续部分。我在这里犯了错误吗?我在这里要做的是def openthedoor(set_accepted_list):
if(((len(set_accepted_list)) >0) & (set_forbidden_list == set()):
print"yes,open the gate"
use_door(1)
else:
print"no,close the gate"
use_door(0)
set_for_comparison = set(set_accepted_list & set_list_ant_id)
list_for_comparison = list(set_for_comparison)
return set_for_comparison,list_for_comparison
def establishing_connection():
print ser.read();
ser.write('1')
last_action = -1
def use_door(activate):
global last_action
if(last_action != activate):
send_data(activate)
last_action = activate
def send_data(data):
if (data ==0):
print "manga"
return True
else:
print "muringa"
return False
def delay_for_goodant(data):
print "thenga"
global ser
try:
if (ser == None):
ser = serial.Serial("COM1",9600,timeout = 0)
print "reconnect"
if send_data(data) is True:
ser.write('0')
time.sleep(0)
incoming_data = ser.readline()
print "python is telling arduino to keep the LED dim"
else:
ser.write('1')
time.sleep(0.7)
incoming_data2 = ser.readline()
print "python is telling the arduino to keep the LED bright"
except IOError:
ser = None
。
if data ==0, i want to ser.write('1')
此外,函数establishing_connection()
set_for_comparison,list_for_comparison = openthedoor(set_accepted_list)
activate = use_door()
data = send_data(activate)
arabica = delay_for_goodant(data)
内的值不会被打印。
这是我得到的,当我运行代码时:
delay_for_goodant