A
A
Alexander Proshchenkov2018-03-31 19:16:49
Python
Alexander Proshchenkov, 2018-03-31 19:16:49

How to return "raw lines" to their previous state?

I get the data from the sqlite database, they are in the form:
"Hello \nworld"
If you write print(abc), it will display Hello \nworld!
How do I get the \n characters to be escaped again?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FeNUMe, 2018-04-01
@FeNUMe

It looks like the database has 'Hello \\nworld!' stored.
In this case, the quick fix is:

#Python 2.X
print '"Hello,\\nworld!"'.decode('string_escape')
#Python 3.X
print(b"Hello,\\nworld!".decode('unicode_escape'))

But it's better to work with the database using an ORM that will do everything for you or google "python unescape string"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question