我有一个返回超过125K行的查询.
目标是编写迭代遍历行的脚本,并为每个行填充第二个表,其中包含从查询结果处理的数据.
为了开发脚本,我用一小部分数据创建了一个重复的数据库(4126行)
在小型数据库上,以下代码有效:
import os
import sys
import random
import mysql.connector
cnx = mysql.connector.connect(user='dbuser', password='thePassword',
host='127.0.0.1',
database='db')
cnx_out = mysql.connector.connect(user='dbuser', password='thePassword',
host='127.0.0.1',
database='db')
ins_curs = cnx_out.cursor()
curs = cnx.cursor(dictionary=True)
#curs = cnx.cursor(dictionary=True,buffered=True) #fail
with open('sql\\getRawData.sql') as fh:
sql = fh.read()
curs.execute(sql, params=None, multi=False)
result = curs.fetchall() #<=== script stops at this point
print len(result) #<=== this line never executes
print curs.column_names
curs.close()
cnx.close()
cnx_out.close()
sys.exit()
Run Code Online (Sandbox Code Playgroud)
该行在curs.execute(sql, params=None, multi=False)大型和小型数据库上都成功.如果我curs.fetchone()在循环中使用,我可以读取所有记录.
如果我改变了这条线:
curs = cnx.cursor(dictionary=True)
Run Code Online (Sandbox Code Playgroud)
阅读:
curs = …Run Code Online (Sandbox Code Playgroud) 我最近拿了免费的 Windows 10,将其升级到 Pro,并安装了 Office 2016 Home。我似乎丢失了所有调试器。
我曾经能够输入:
"%windir%\SysWOW64\cscript.exe" "TestScript.vbs" //d //x
Run Code Online (Sandbox Code Playgroud)
在 Windows 7 及更高版本中会弹出调试器。这一切似乎都被删除了——甚至连调试器 clsid 也不见了。
我不想安装 Visual Studio——有没有办法让极简调试器回来?
fh = logging.FileHandler('example.log',delay = True)
fh.setLevel(logging.INFO)
Run Code Online (Sandbox Code Playgroud)
由于延迟为True,除非记录某些内容,否则永远不会写入文件.此时,文件中的第一行是第一个记录,它将包含asctime,levelname等元素
使用python 2.7.10,是否有一种理智的方法来在第一次写入不包含这些元素的记录时添加一行(或两行)?
我可以在使用它进行日志记录之前写入该文件,但如果我这样做,我最终会将日志留空但是标题.
所需的输出可能如下所示:
Using test.fil with option 7
2015-11-01 13:57:58,045 :log_example: INFO fn:main result:process 4 complete --7 knights said ni
2015-11-01 13:57:58,045 :log_example: INFO fn:main result:process 3 complete --3 bunnies attacked
Run Code Online (Sandbox Code Playgroud)
谢谢,