我有这个代码
operator delete[]
每次运行此代码时,它只会在def base()中打印ada_dosen函数,如果我用ctrl + c停止它,这里是追溯
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
任何ide什么错误所以我的def base()上的所有函数都在运行?
答案 0 :(得分:0)
您的代码中存在一些问题,以突出显示一些问题 -
您的所有功能都定义为def <function name>()
,您没有结尾:
,如果没有,您很可能会遇到语法错误。
您已将base
函数定义为def base()
,但在程序的主要部分中,您尝试通过将nomor
作为{{{{}}来调用它。 1}},我认为您需要更改函数定义以接受参数为 - base(nomor)