擅长:python、mysql、java
<p>如果不想将每个条目提交到数据库,可以添加以下行:</p>
<pre><code>conn.autocommit = True
</code></pre>
<p>所以你得到的代码是:</p>
<pre><code>import psycopg2
try:
conn = psycopg2.connect("dbname='djangostack' user='bitnami' host='localhost' password='password'")
conn.autocommit = True
except:
print "Cannot connect to db"
cur = conn.cursor()
try:
cur.execute("""insert into cnet values ('r', 's', 'e', 'c', 'w', 's', 'i', 'd', 't')""")
except:
print "Cannot insert"
</code></pre>