Распечатать читаемый формат из строки, содержащей \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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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