心理2连接关闭()导致语法

2024-09-11 00:40:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个功能:

conn = psycopg2.connect("dbname=test user=t password=test host=localhost")
cur = conn.cursor()
n=re.compile(r"(Number of atoms\s*:?\s*([0-9]+))")
f = open(filename,'rb')
new=open("coord.txt",'w')
while True:
    line = f.readline()
    nA=n.search(line)
    if nA != None:
       new.writelines(nA.group(0)+"\n")
binaryC=new.read()
cur.execute("INSERT INTO fhi(archivo) VALUES (%s)",(psycopg2.Binary(binaryF),))
conn.commit()
new.close()
cur.close()
conn.close()

当我运行它时,我得到这个错误

^{pr2}$

我看不出错误,请帮帮我


Tags: test功能newcloseconnect错误linepassword
1条回答
网友
1楼 · 发布于 2024-09-11 00:40:30

代码真是一团糟。。。在

我假设上面有更多的上下文,这就是问题所在(可能缺少一个结束语)。在这个特定的片段中没有语法问题,但是有大量的样式问题(这可能隐藏语法问题)。在

请考虑运行某种linter(pyflakes、pep8等),以确保代码的样式是一致的。总的来说,这会让你的生活更轻松。在

相关问题 更多 >