我刚刚找到了用于将 Python 连接到 MySQL 数据库的 pymysql 模块。我有一个数据库,其中有一个名为“loot”的表,loot 包含一个名为“wins”的列。我的代码包含一个名为 'won' 的变量,该变量在 SQL 行之前被赋予一个值。我希望将变量 'won' 输入到 id=1 的 'wins' 列中。id=1 行已存在于数据库中。
下面的代码抛出一个错误 pymysql.err.InternalError: (1054, "Unknown column 'won' in 'field list'")
我的问题:为什么我会收到这个错误,我做错了什么?
编码:
import pymysql
# Open database connection
db = pymysql.connect(host='*******',user='******',password='*****',db='******')
# prepare a cursor object using cursor() method
cursor = db.cursor()
won=1
# Prepare SQL query to UPDATE required records
sql = "UPDATE loot SET wins = won WHERE id = 1"
# Execute the SQL command
cursor.execute(sql)
# Commit …Run Code Online (Sandbox Code Playgroud) 我使用 pyautogui 和 pytesseract 的组合来捕获屏幕上的小区域,然后将数字/文本拉出该区域。我编写的脚本可以完美地读取大多数捕获的图像,但个位数似乎会导致问题。例如,包含数字的图像的小区域被保存到 .png 文件中,数字 11、14 和 18 被完美地拉出,但数字 7 只是作为一个空字符串返回。
问题: 什么可能导致这种情况发生?
代码:大幅缩减以使其易于遵循:
def get_text(image):
return pytesseract.image_to_string(image)
answer2 = pyautogui.screenshot('answer2.png',region=(727, 566, 62, 48))
img = Image.open('answer2.png')
answer2 = get_text(img)
Run Code Online (Sandbox Code Playgroud)
此代码重复 4 次,每个图像一次,它适用于 11、14、18,但不适用于 7。
只是为了减慢这里读取的文件的速度,这里是通过屏幕截图命令保存图像后的屏幕截图。
https://gyazo.com/0acbf5be2d970abeb29561113c171fbe
这是我正在工作的屏幕截图:
我在下面的代码中得到'NoneType'对象不是可迭代的TypeError.下面的代码是使用pyautogui滚动数字文件夹中的10个图像(名称为0到9,以图像中的#命名),当它找到一个时,报告x的值以及它找到的数字.然后按x值对字典进行排序,以读取图像中找到的数字.
问题:我还在学习Python,这个TypeError让我st脚,我怎么能纠正这个?
#! python3
import sys
import pyautogui
# locate Power
found = dict()
for digit in range(10):
positions = pyautogui.locateOnScreen('digits/{}.png'.format(digit),
region=(888, 920, 150, 40), grayscale=True)
for x, _, _, _ in positions:
found[x] = str(digit)
cols = sorted(found)
value = ''.join(found[col] for col in cols)
print(value)
Run Code Online (Sandbox Code Playgroud)
回溯错误:
Traceback (most recent call last):
File "C:\Users\test\python3.6\HC\power.py", line 10, in <module>
for x, _, _, _ in positions:
TypeError: 'NoneType' object is not iterable
Run Code Online (Sandbox Code Playgroud)