0

Python新手在这里...我想从for循环创建一个新元组。元组将在IN子句中的 MySQL 选择查询中使用。它工作不正确,告诉我我有以下问题cur.execute

TypeError: not all arguments converted during string formatting

check_tz = []
for tz in pytz.common_timezones:
    if now_utc.astimezone(timezone(tz)).strftime('%H') == '01':
        check_tz.append(tz)

print check_tz

# Prints out something as follows. I cut the output short for the sake of this example.
# ['America/Anguilla', 'America/Antigua', 'US/Eastern']

cur.execute("SELECT * FROM users where timezone IN (%s)", check_tz)

for row in cur.fetchall():
    print row[0]
4

1 回答 1

1

您可能需要将时区列表转换为字符串:

cur.execute("SELECT * FROM users where timezone IN (%s)", ','.join(map(lambda x: "'%s'" % x, check_tz))
于 2013-07-12T05:39:35.083 回答