sqlite按原样保存文本文件和输出:python

2024-04-26 00:02:47 发布

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

我试图用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}$

我怎样才能得到原始文件中的代码?在

谢谢

阿比纳夫


Tags: 文件textfromexecutesqlitecodejavaconn