我试图用python在sqlite中保存一个文本文件,但是当我试图检索文件时,我看到了换行符和其他字符。有没有什么方法可以像原始文件一样输出文件?有什么办法吗。在
import sqlite3
conn=sqlite3.connect('example.db')
c=conn.cursor()
c.execute("create table code_tag1 (language text, code BLOB, tag text)")
#c.execute("select * from sqlite_master")
with open("bubblesort_java.txt","rb") as f:
ablob=f.read()
c.execute("insert into code_tag1 values('java',?,'bubblesort')",[buffer(ablob)])
conn.commit()
row=c.execute("select * from code_tag1").fetchone()
print (repr(str(row[1])))
conn.close()
输出为:
^{pr2}$我怎样才能得到原始文件中的代码?在
谢谢
阿比纳夫
输出没有问题。您正在打印字符串的
repr
,这就是它显示\r
,\n
等的原因相关问题 更多 >
编程相关推荐