私はPythonで、次のような問題点がありますが、私は考えている理由::Pythonのさえずり "NameErrorグローバル名 'SERは' が定義されていない"
"Traceback (most recent call last): File
C:/Users/W7-32/Downloads/TW31.py", line 82, in <module>
driptwit() ## Llamada a la funcion driptwit File "C:/Users/W7-32/Downloads/TW31.py", line 71, in driptwit
ser.write("1") NameError: global name 'ser' is not defined
ソースコード:
# lIBRERIAS
import twitter
import tweepy
import serial
import time
import threading
import os
import datetime
##Consumer y Access de Twitter Developers from tweepy import API
consumer_key = 'QpaLpmQOS0DMTt2hFxy5WN40i'
consumer_secret = 'WoUssPI9gIdiEIu0LSWG2bvGuAlvF8WTDStdFTkj5OIPwbeLth'
access_token_key = '935906436-aMBTKoPOZshZhCRRil1vNCTUKPxQBSiuXe181hLp'
access_token_secret = 'pxYs26cMqxQbhxQtgfIGnUjWGP1eLlK9mVxdaLeorPfZ4'
#Autenticacion y conexion con Twitter
#auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
##auth.set_access_token(access_token_key, access_token_secret)
#api = tweepy.api(consumer_key, consumer_secret, access_token_key, > access_token_secret)
#api=tweepy.API(auth)
##Declaracion del puerto serial
auth=tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
api=tweepy.API(auth)
locations = ['COM3','COM4','COM5','COM6']
for device in locations:
try:
ser = serial.Serial(device, baudrate=9600, bytesize=8,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE)
print ("\nArduino found on: " + ser.portstr + " please > wait...\n")
time.sleep(2)
break
except:
print "Failed to connect on", device
## check serial port
def checkokay():
ser.flushInput()
time.sleep(3)
line = ser.readline()
time.sleep(3)
if line == ' ':
line = ser.readline()
print("here")
print('Bienvenido a Print_Twitter')
def driptwit():
status = []
x = 0
status = api.user_timeline('FerCMejia') ##grab latest statuses
checkit = [s.text for s in status] ##put status in an array
drip = checkit[0].split() ##split first tweet into words
## check for match and write to serial if match
if (drip[0] == '#dripPrint'):
print("Recibiendo Twitter, Imprimiendo")
ser.write("1")
else:
if drip[0] == '#dripPrintStop': ##break if done
ser.write("0")
print("Impresion detenida, esperando instruccion")
else:
print("Esperando Tweet")
ser.write("0")
while 1:
driptwit() ## Llamada a la funcion driptwit
time.sleep(20) ## Espera de 20 seg para volver a leer el status
ポートにはArduinoが接続されていますが、それは私には定義されていないというエラーを与えます。
私はPycharmとPython2.7インタプリタ、のWindows7 32ビットを使用します。
は、ここでの.pyアーカイブです。
あなたのコードをあなたの質問に示してください。ほとんどの場合、スペルが間違っているか範囲外の名前を使用しようとしている可能性があります。 – cdarke
Seconded。メガのようなリンクが不審であるという事実に加えて、あなたは社会が自由に助けるためにその時間を与えることを考えると、むしろ同じことをやって私たちの時間を過ごすに私たちを尋ねるよりも、問題を特定するために[MCVE]にコードを減らす必要があります。 –
準備完了、それが正しい?ありがとう!! –