0
我正在使用python程序將數據記錄到MySQL數據庫。數據庫連接已建立,但在寫入日誌時出現以下錯誤Type Error: format requires a mapping
。Python不寫入MySQL(類型錯誤:格式需要映射)
感興趣的代碼如下:
MySQL表:
CREATE TABLE pidRun
(
pidKey INT auto_increment PRIMARY KEY,
pidSetPoint INT,
pidMeasure FLOAT,
pidError FLOAT,
integrator FLOAT,
derivator FLOAT
);
Python代碼:
# Insert a new line to table pidRun
add_pidRun = ("INSERT INTO pidRun "
"(pidSetPoint, pidMeasure, pidError, integrator, derivator)"
"VALUES (%(pidSetPoint)i, %(pidMeasure)f, %(pidError)f, %(integrator)f, %(derivator)f)")
然後將代碼插入在必要的點線是在這裏:
data_pidRun = (pidControl.getPoint(), centSpeed, errSpeed, 0.0, 0.0) cursor.execute(add_pidRun, data_pidRun) dBase.commit()
pidControl.getPoint是一個整數
centSpeed是浮法
errspeed是浮法
任何方向是真正理解。
完美。我需要確定爲什麼我應該在列表中使用元組! –