Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Python不';从Sqlite查询时是否转换\n为换行符?_Python_Mysql_Sqlite_Pyqt - Fatal编程技术网

为什么Python不';从Sqlite查询时是否转换\n为换行符?

为什么Python不';从Sqlite查询时是否转换\n为换行符?,python,mysql,sqlite,pyqt,Python,Mysql,Sqlite,Pyqt,我想从Sqlite查询并包含\n,我希望python将其转换为换行符,但它没有。我还在数据库中将\n更改为\n,但仍然无法转换 cursor.execute('''SELECT test FROM table_name ''') for row in cursor: self.ui.textEdit.append(row[0]) # or print row[0] 我还尝试了unicode(行[0]),但没有成功。我很惊讶在网络上没有一个简单的

我想从Sqlite查询并包含\n,我希望python将其转换为换行符,但它没有。我还在数据库中将\n更改为\n,但仍然无法转换

cursor.execute('''SELECT test FROM table_name ''')
for row in cursor:
        self.ui.textEdit.append(row[0])
        # or 
        print row[0]

我还尝试了
unicode(行[0])
,但没有成功。我很惊讶在网络上没有一个简单的解决方案

SQLite和Python都不能转换字符串中的字符(源代码中编写的Python字符串中的转义除外)。 如果正确处理换行符,则换行符可以正常工作:

>>> import sqlite3
>>> db = sqlite3.connect(':memory:')
>>> c = db.cursor()
>>> c.execute('create table t(x)')
>>> c.execute("insert into t values ('x\ny')")
>>> c.execute("insert into t values ('x\\ny')")
>>> c.execute("select * from t")
>>> for row in c:
...   print row[0]
...
x
y
x\ny

如果是文字'\n',则不会。@jayanth ok,但即使是它也不能与\\n一起使用