IHAVE這個代碼任何想法我的python代碼有什麼問題?
import serial
import time
import datetime
import MySQLdb as mdb
localtime = time.localtime(time.time())
port = serial.Serial("/dev/ttyUSB0", baudrate=9600)
count = 0
nomor =''
start = '\x02'
stop = '\x03'
def mulai():
print "Silahkan tempel kartu anda"
def no_dosen()
print "Dosen tidak terdaftar"
mulai()
def no_jadwal()
print "Tidak ada jadwal kuliah"
mulai()
def ada_dosen(dosen)
print dosen
return
def ada_matkul(matkul)
print matkul
return
def cek_dosen(no)
db = mdb.connect("localhost", "azis48", "azis48", "skripsi")
cur = db.cursor()
cond1 = "SELECT * FROM dosen WHERE kode_dosen = %s" %(no)
try:
cur.execute(cond1)
hitung = cur.rowcount
res1 = cur.fetchall()
for row in res1:
nama_dosen = row[1]
if hitung == 1:
return nama_dosen
elif hitung != 1:
return 'null'
except:
db.close()
def cek_jadwal(day,time)
db = mdb.connect("localhost", "azis48", "azis48", "skripsi")
cur = db.cursor()
cond2 = "SELECT nama_mk FROM jadwal WHERE hari = '%s' AND waktu = '%s'" %(day,time)
try:
cur.execute(cond2)
hitung = cur.rowcount
res2 = cur.fetchall()
for row in res2:
nama_mk = row[1]
if hitung == 1:
return nama_mk
elif hitung != 1:
return 'null'
except:
db.close()
def cek_pertemuan(matkul)
db = mdb.connect("localhost", "azis48", "azis48", "skripsi")
cur = db.cursor()
cond3 = "SELECT pertemuan_ke FROM acara WHERE nama_mk = '%s'" %(matkul)
try:
cur.execute(cond3)
res3 = cur.fetchall()
for row in res3:
pertemuan_ke = row[0]
return pertemuan_ke
except:
db.close()
def base()
day = localtime.tm_wday
time = localtime.tm_hour
no = str(nomor)
dosen = cek_dosen(no)
if dosen == 'null':
no_dosen()
elif dosen != 'null':
ada_dosen()
matkul = cek_jadwal(day,time)
if matkul == 'null':
no_jadwal()
elif matkul != 'null':
ada_matkul()
pertemuan = cek_pertemuan(matkul)
print pertemuan
mulai()
if __name__ == '__main__':
mulai()
while True:
data = port.read()
count += 1
if count == 1:
if str(data) != start:
nomor = ''
count = 0
elif 2 <= count <= 13:
nomor = nomor + str(data)
elif count == 16 and str(data) == stop:
base(nomor)
nomor = ''
count = 0
每次我運行這段代碼,它只是從所有在高清基地(打印ada_dosen功能),如果我用Ctrl停止+ C這裏是回溯
DOSEN3
Traceback(most recent call last):
file "skripsi.py", line 111, in<module>
base(nomor)
任何IDE什麼是錯的,所以我的def base()運行的所有功能?
請添加完整的追溯,好像你只增加部分回溯 –
基地的定義()不容許任何變量被作爲參數傳遞。因此,無論是添加一些東西到參數列表或刪除傳遞的參數。 – stunningpotato
此外,下次請使用最小示例幷包含整個Traceback,以便其他人可以更輕鬆地理解您的代碼。 – stunningpotato