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