简体   繁体   English

我不希望psycopg2在查询结果中转义换行符(\\ n)

[英]I don't want psycopg2 to escape new line character (\n) in query result

I have some records data with \\n . 我有一些记录数据\\n When I do a SELECT query using psycopg2 the result comes with \\n escaped like this \\\\n . 当我使用psycopg2进行SELECT查询时,结果带有\\n这样的\\\\n转义。 I want the result have literal \\n in order to use splitlines() . 我希望结果具有文字\\n以便使用splitlines()

The point is that values were edited with pgadmin3 (incorrectly, the correct way is shift+enter to add a new line). 关键是值是使用pgadmin3编辑的(错误地,正确的方法是shift + enter添加新行)。 I asked the user to use phppgadmin (easier for him, multiline fields are edited with textarea control) and now everything is working properly. 我要求用户使用phppgadmin(对他来说更容易,使用textarea控件编辑多行字段),现在一切正常。

So pyscopg2 WORKS fine, I'm sorry to thought it was the culprit. 所以pyscopg2 工作得很好,我很遗憾地认为这是罪魁祸首。

He was putting literals \\n in order to put new lines. 他正在使用文字\\n来添加新行。

Try this: object.replace("\\\\n", r"\\n") 试试这个: object.replace("\\\\n", r"\\n")

Hope this helped :) 希望这有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM