gpt4 book ai didi

python - 如何用一个输入创建不同的条件(python)

转载 作者:搜寻专家 更新时间:2023-10-30 22:34:38 25 4
gpt4 key购买 nike

谁能帮我写代码?

我想将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com