python - Xcode 4.2(内部版本 4D199)+ Python : Console output is different to the expected (e. g。没有 UTF-8 字符)

标签 python xcode utf-8 xcode4.2

我在 Mac OS X 10.7.2 上的 Xcode 4.2(内部版本 4D199)中使用 Python 3.2.2,如下所示:

ma​​in.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/

相关文章:

python - 使用 pygtk 设置图像在窗口中的位置

python - 我们如何在 jsonpath_ng python 中使用正则表达式过滤器,它将/视为排序方向。有什么替代方案吗?

ios - 将 Xcode 项目注册到 Bluemix

java - 如何找出字符串是否已经被 URL 编码?

C# Encoding.UTF8 弄乱了字节 []

python - 数据在我的 django 模板中无法正确显示

python - 在python中压缩数组?

objective-c - 从 View Controller 外部调用 macOS 中的 View

ios - UIFont 为自定义字体返回 nil

mysql - rails、mysql 字符集和编码 : binary