报错内容:
Traceback (most recent call last):
File "test.py", line 97, in <module>
out_tgt.write('%s\n' % rows)
TypeError: not all arguments converted during string formatting
Exception ignored in: <function BufferedFile.del at 0x7f56b3e157a0>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/paramiko/file.py", line 66, in del
File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 1392, in close
File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 991, in shutdown_write
File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 963, in shutdown
File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 1246, in _send_eof
File "/usr/local/lib/python3.7/site-packages/paramiko/message.py", line 232, in add_int
TypeError: 'NoneType' object is not callable
部分代码:
conn1 = pymysql.connect(**conninfo)
cursor = conn1.cursor()
get_tgt = open(config.path + '/' + case_id + "_tgt.sql", "r")
out_tgt = open(out_path1, 'w')
while (True):
all_tgt = get_tgt.readline()
tgt_sql = all_tgt.lstrip()
regex = r"[1][s|S][e|E][l|L].\n"
if (all_tgt == ''):
break
if re.search(regex, tgt_sql):
cursor.execute(tgt_sql)
rows = cursor.fetchall()
out_tgt = open(out_path1, 'a')
out_tgt.write('%s\n' % rows)
请大佬们帮忙看一下 是哪里的问题应该如何修改?谢谢
将out_tgt.write('%s\n' % rows)语句改为out_tgt.write('%s\n' % (rows,)) ,脚本执行成功。
%s 只能作用于字符串 你试试将rows循环 然后调用out_tgt.write()方法
你好,代码我又补充了一下,后面有将rows循环.不过执行的时候还是会报错.
@日常云吸猫: if re.search(regex, tgt_sql):
cursor.execute(tgt_sql)
rows = cursor.fetchall()
out_tgt = open(out_path1, 'a')
out_tgt.write('%s\n' % rows)
将这块的循环一下
@Jruing: 谢谢解答! 不用麻烦了。把出问题的那条语句改为了out_tgt.write('%s\n' % (rows,)) 运行没有再报错。