【发布时间】:2018-01-19 15:32:01
【问题描述】:
我想清理代码中的原始语句,并将它们作为 sql 文件添加到另一个目录中的单独文件中。
所以想运行下面的代码:
read_cursor.execute('INSERT OR IGNORE INTO quantity VALUES (?,?,?)', row)
但将其更改为:
read_cursor.execute('sqlstatements/quantity.sql', row)
这可能我该怎么做?
【问题讨论】:
-
嗯,类似
read_cursor.execute(open('sqlstatements/quantity.sql').read(), row)?虽然这是一个肮脏的解决方案,但您应该关注this answer 来了解如何读取文件。