我在 Mac OS X 10.7.2 上的 Xcode 4.2(内部版本 4D199)中使用 Python 3.2.2,如下所示:
main.py
#coding=utf-8
print("ľťď", 1+1)
print("ľťď")
控制台中的输出(Shift+Cmd+C):
('\xc4\xbe\xc5\xa5\xc4\x8f', 2)
ľťď
预期输出(例如 IDLE 运行良好):
ľťď 2
ľťď
现在考虑到它还包含括号、撇号和逗号,我认为这种行为是控制台调试性质的结果,因此真正的问题可能是如何使控制台显示最终输出。然而,这种行为似乎有点不一致,因为这是我第一次接触 Xcode 和 Python,所以我的问题相当广泛。
TL;DR: 是否可以使 Xcode 的控制台输出与例如相同的输出:空闲?
最佳答案
Now given the fact that it also includes the brackets, apostrophes and comma, I presume that this behaviour is a result of the console's debugging nature
事实并非如此。这就是Python 2和3之间的区别。
$ python2
>>> print("ľťď", 1+1)
('\xc4\xbe\xc5\xa5\xc4\x8f', 2)
$ python3
>>> print("ľťď", 1+1)
ľťď 2
您实际上正在运行两个不同的 Python 版本。由于 Python 3 不向后兼容,因此您应该为您的项目选择 2 或 3 并坚持使用。
关于python - Xcode 4.2(内部版本 4D199)+ Python : Console output is different to the expected (e. g。没有 UTF-8 字符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8636248/