问题:
报错内容:
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)
请大佬们帮忙看一下 是哪里的问题应该如何修改?谢谢
回答1:
将out_tgt.write('%s\n' % rows)语句改为out_tgt.write('%s\n' % (rows,)) ,脚本执行成功。
回答2:
%s 只能作用于字符串 你试试将rows循环 然后调用out_tgt.write()方法