Распечатать читаемый формат из строки, содержащей \n и другие юникоды.Python

Программы на Python
Anonymous
Распечатать читаемый формат из строки, содержащей \n и другие юникоды.

Сообщение Anonymous »

Изначально это сообщение было набором, а затем я преобразовал его в строку с помощью str(a)

Код: Выделить всё

a = "Let\u2019s trade!\n\u00a0\n\nAn Old Friendship, A New Day!\nHere comes the old, visiting at your home.\nIt comes with a new story, about how to live the present, about how in his past he did wrong.\n\nThe new day shines andx2"
и почему-то при печати

Код: Выделить всё

print(a)
он ​​сохраняет все символы \n и \u2019 и не форматирует их в новую строку или \u2019 в правую кавычку " ' ", поэтому он просто отображается в виде открытого текста:

Код: Выделить всё

Let\u2019s trade!\n\u00a0\n\nAn Old Friendship, A New Day!\nHere comes the old, visiting at your home.\nIt comes with a new story, about how to live the present, about how in his past he did wrong.\n\nThe new day shines andx2
обычно:

Код: Выделить всё

print("Let\u2019s trade!\n\u00a0\n\nAn Old Friendship, A New Day!\nHere comes the old, visiting at your home.\nIt comes with a new story, about how to live the present, about how in his past he did wrong.\n\nThe new day shines andx2")
он ​​выведет это как:

Код: Выделить всё

Let’s trade!
 

An Old Friendship, A New Day!
Here comes the old, visiting at your home.
It comes with a new story, about how to live the present, about how in his
past he did wrong.

The new day shines and
Как это исправить?

Подробнее здесь: https://stackoverflow.com/questions/502 ... r-unicodes

Вернуться в «Python»