How to print a variable having non-English characters to the command prompt using Python

一世执手 提交于 2021-02-11 12:36:07

问题


I have a python program that generates a string in Tamil language. For example, the string could be தமிழ் . I could write this exactly as it appears here to a text file by using utf-8 at the time of opening the file. But when I write the same string variable to stdout using print() function it displays 3 what(?) characters surrounded by boxes. I have seen printing of literals like print(b'\xc2\xb5'.decode()) and print (u'\u0420\u043e\u0441\u0441\u0438\u044f') happening properly. But the issue arises when I try to print to stdout a text string variable like this. How can I solve this problem? My platform is Windows 10.


回答1:


  1. Go to Region & Language Settings via the Search Bar and add the Tamil language. Below I have added Chinese as an example because I am studying it:

Languages section of Settings

  1. Open a terminal and make sure your language is selected in the language bar:

Language selection in notification area

  1. Open the "Command Prompt" properties and make sure to select one of the new fonts that should appear to support your language.

Command prompt Properties

  1. Type something in the language to test it:

command prompt example



来源:https://stackoverflow.com/questions/63867433/how-to-print-a-variable-having-non-english-characters-to-the-command-prompt-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!