11
這是我目前有:如何在Python中將sqlite導出爲CSV而不被格式化爲列表?
conn = sqlite3.connect(dbfile)
conn.text_factory = str ## my current (failed) attempt to resolve this
cur = conn.cursor()
data = cur.execute("SELECT * FROM mytable")
f = open('output.csv', 'w')
print >> f, "Column1, Column2, Column3, Etc."
for row in data:
print >> f, row
f.close()
它會創建一個CSV,看起來像這樣的輸出文件:
Column1, Column2, Column3, Etc.
(1, u'2011-05-05 23:42:29',298776684,1448052234,463564768,-1130996322, None, u'2011-05-06 04:44:41')
我不想讓行是在括號中也沒有引號也沒有字符串之前的'u'。我如何得到它沒有所有這些寫入行到csv?謝謝,
這樣做,謝謝! – Dan