作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
谁能帮我写代码?
我想将 RFID 卡数据插入 MySQL 数据库。当我第一次点击 RFID 阅读器上的标签时,程序会将数据插入 Masuk 表当我再次点击标签时,程序会将数据插入 Keluar 表。
我是否正确使用了这段代码?
import MFRC522
import signal
import time
import MySQLdb
import datetime
db = MySQLdb.connect(host='localhost',
user='root',
passwd='12345678',
db='pa')<br>
cursor = db.cursor()
continue_reading = True
MIFAREReader = MFRC522.MFRC522()
cardA = [131,89,173,1,118]
def read ():
read = 1
def end_read(signal, frame):
global continue_reading
continue_reading = False
print "Ctrl+C captured, ending read."
MIFAREReader.GPIO_CLEEN()
signal.signal(signal.SIGINT, end_read)
while continue_reading:
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
if status == MIFAREReader.MI_OK:
print "Card detected"
(status,backData) = MIFAREReader.MFRC522_Anticoll()
if status == MIFAREReader.MI_OK:
print "Card read UID: "+str(backData[0])+""+str(backData[1])+""+str(backData$
if backData == cardA:
print "Selamat Datang Dheny"
if (read == True):
sql = """ INSERT INTO Masuk(Nama, No_ID, datetime) VALUES ('Dheny', $
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
read = False
if (read == False):
sql = """ INSERT INTO Keluar(Nama, No_ID, datetime) VALUES ('Dhe$
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
read = True
最佳答案
查看访问和修改全局变量的代码
global count
def modi():
global count # required to modify the global copy
count=10
def printc():
if (count==10): # read it as a normal variable
print("yes")
modi()
printc()
关于python - 如何用一个输入创建不同的条件(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38801851/
我是一名优秀的程序员,十分优秀!