此主题已被涵盖。如果是这样,为此道歉。从数据库中获取行(使用“for”和“while”循环)并从控制台执行脚本时遇到问题。Py:从数据库提取并从控制台执行脚本时限制
我需要从数据库中获取大量的行,我正在构建一个脚本,以便我可以插入用户标识,并且我将获取客户端和状态的帐户标识。 我已经意识到,当我从Eclipse运行脚本时,完整的输出从DB中获取。当我从控制台运行脚本时,行数有限制。所以,我想知道如果我有一个“while行不是无”循环...为什么我的行变成无如果数据库中有更多的行?
另外:我需要解决这个问题。不管怎样。我宁愿不将完整列表加载到本地文件(如果可能)。但是,如果没有其他方式......好吧,请帮助!这是我的例子。
#!/usr/bin/env python3
# encoding: utf-8
import configparser
import pymysql
from prettytable import PrettyTable
conn = pymysql.connect(host=host, user=user, passwd=password, db=database)
print()
userid = input('Insert User ID(s) > ') # userid is a list of 2000 users in comma-separated format
userids = userid.replace(" ", "").replace("'", "").replace(",", "','")
cur = conn.cursor()
cur.execute(""" SELECT user_ID, account_ID, status FROM Account WHERE user_ID IN ('%s'); """ % userids)
rows = cur.fetchall()
table = PrettyTable(["user_ID", "account_ID", "status"])
table.padding_width = 1
for line in rows:
user_ID = str(line[0])
account_ID = str(line[1])
status = str(line[2])
table.add_row([user_ID, account_ID, status])
print()
print(table)
conn.close()
print()
print()
exit()