这是我第一次来这里,而且我对 Python 世界还是个新手。我也在学习中文,我想创建一个程序来使用字典复习中文词汇。这是我通常使用的代码:
#!/usr/bin/python
# -*- coding:utf-8-*-
dictionary = {"Hello" : "你好"} # Simple example to save time
print(dictionary)
我不断得到的结果是这样的:
{'hello': '\xe4\xbd\xa0\xe5\xa5\xbd'}
我还尝试在带有汉字的字符串的开头添加一个“u”,甚至方法“.encode('utf-8” '),但我通常在 Geany IDE 上工作,我尝试检查所有首选项,并且我已阅读 PEP 网页 以及发布的许多其他问题很有趣,它适用于字符串和 raw_input 方法,但没有其他...
so this is my first time here, and also I am new to the world of Python. I am studying Chinese also and I wanted to create a program to review Chinese vocabulary using a dictionary. Here is the code that I normally use:
#!/usr/bin/python
# -*- coding:utf-8-*-
dictionary = {"Hello" : "你好"} # Simple example to save time
print(dictionary)
The results I keep getting are something like:
{'hello': '\xe4\xbd\xa0\xe5\xa5\xbd'}
I have also trying adding a "u" to the beginning of the string with the Chinese characters, and even the method ".encode('utf-8'), yet no of these seem to work. I normally work off of the Geany IDE. I have tried to check out all of the preferences, and I have read the PEP web page along with many of the other questions posted. It is funny, it works with strings and the raw_input method, but nothing else...
发布评论
评论(2)
打印字典时(例如
print(dictionary)
),会显示键和值的repr
。相反,尝试:
产量:
When printing a dict, (e.g.
print(dictionary)
), therepr
s of the keys and values are displayed.Instead, try:
yields:
如果直接打印值,您可以看到字符:
You can see the characters if you print the values directly: