简体   繁体   English

Xcode 4.2(内部版本4D199)+ Python:控制台输出与预期的不同(例如,没有UTF-8字符)

[英]Xcode 4.2 (build 4D199) + Python: Console output is different to the expected (e.g. no UTF-8 characters)

I am using Python 3.2.2 in Xcode 4.2 (build 4D199) on Mac OS X 10.7.2 and as follows: 我在Mac OS X 10.7.2上的Xcode 4.2(内部版本4D199)中使用Python 3.2.2,如下所示:

main.py main.py

#coding=utf-8
print("ľťď", 1+1)
print("ľťď")

Output in the console (Shift+Cmd+C): 在控制台中输出(Shift + Cmd + C):

('\xc4\xbe\xc5\xa5\xc4\x8f', 2)
ľťď

Expected output (eg IDLE works well): 预期的输出(例如,IDLE运行良好):

ľťď 2
ľťď

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, hence the real question is probably how to make the console to show the final output. 现在考虑到它也包含方括号,撇号和逗号,我认为这种行为是控制台调试性质的结果,因此,真正的问题可能是如何使控制台显示最终输出。 The behaviour however seems a bit inconsistent and since this is my first encounter with Xcode and Python, my question is rather broad. 但是,该行为似乎有点不一致,并且由于这是我第一次接触Xcode和Python,因此我的问题相当广泛。

TL;DR: Is it possible to make the Xcode's console to output the same as eg IDLE? TL; DR:是否可以使Xcode的控制台输出与例如IDLE相同的内容?

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 现在考虑到它也包含方括号,撇号和逗号,我认为这种行为是控制台调试性质的结果

It's not. 不是。 This is the difference between Python 2 and 3. 这是Python 2和3之间的区别。

$ python2
>>> print("ľťď", 1+1)
('\xc4\xbe\xc5\xa5\xc4\x8f', 2)

$ python3
>>> print("ľťď", 1+1)
ľťď 2

You're actually running two different Python versions. 您实际上正在运行两个不同的Python版本。 Since Python 3 is not backwards compatible, you should pick either 2 or 3 for your project and stick with it. 由于Python 3不向后兼容,因此您应该为项目选择2或3并坚持使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM