方法一:
导入新特性
# Python 2.x compatiblefrom __future__ import print_function
方法二:
使用类似 print 功能的函数兼容 Python2 和 Python3
# Python 2.x & 3.x compatiblefrom distutils.log import warn as printfprintf('Hello World!')
另一种方案(无缓冲的输出):
# Python 2.x & 3.x compatibleimport syssys.stdout.write('Hello World!\n')
