Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些记录数据\n。当我使用 psycopg2 进行 SELECT 查询时,结果会\n像这样转义\\n。我希望结果有文字\n以便使用splitlines().
\n
\\n
splitlines()
关键是值是用 pgadmin3 编辑的(不正确,正确的方法是 shift+enter 添加新行)。我要求用户使用 phppgadmin(对他来说更容易,使用 textarea 控件编辑多行字段),现在一切正常。
所以 pyscopg2 工作得很好,我很抱歉认为这是罪魁祸首。
他正在输入文字\n以添加新行。
试试这个:object.replace("\\n", r"\n")
object.replace("\\n", r"\n")
希望这有帮助:)