2

I use Python 3.4, the Windows console, and chcp 65001 (font consolas).

This is my code:

print("%s" % "ô ô")

result:

ô ô

But when i print more unicode character, it's auto make a newline:

print("%s" % "ô ô ô")

ô ô ô
�


print("%s" % "ô ô ô ô")

ô ô ô ô
ô

And my question is:

  • Why?
  • How to print a unicode string in one line?
Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
pc43
  • 439
  • 1
  • 7
  • 19
  • Not reproducing for me in Python 3.4.3 , in windows 7. Are you sure that is the exact code that is reproducing the issue for you? Could it be part of a larger code? – Anand S Kumar Jul 21 '15 at 05:16
  • do you use CMD?, my code is only 2 line: # -*- coding: utf-8 -*- and print("%s" % "ô ô ô ô") – pc43 Jul 21 '15 at 05:19
  • Yes i am running from command line, (I ran using a script as well) still same, not sure if someone else can reproduce. – Anand S Kumar Jul 21 '15 at 05:21
  • do you use chcp 65001 and font consolas? , i ran from a file ".py" – pc43 Jul 21 '15 at 05:22
  • 3
    Codepage 65001 (UTF-8) doesn't work in the Windows console. There are various bugs across Windows and C runtime versions. In this case it's returning the number of UTF-16 codes written to the console's internal screen buffer instead of the number of UTF-8 bytes written. Use the wide-character API instead, e.g. via [win-unicode-console](https://github.com/Drekin/win-unicode-console). – Eryk Sun Jul 21 '15 at 05:23
  • possible duplicate of [Windows cmd encoding change causes Python crash](http://stackoverflow.com/questions/878972/windows-cmd-encoding-change-causes-python-crash) — The crash has been fixed since but printing Unicode strings is indeed still broken. – roeland Jul 21 '15 at 22:34
  • Another similar question, although not specifically about python 3 is here: http://stackoverflow.com/questions/30923819/why-python-2-7-on-windows-need-a-space-before-unicode-character-when-print. cp65001 has indeed all sorts of weird bugs. – roeland Jul 22 '15 at 00:55

0 Answers0