小编Qoo*_*Qoo的帖子

类型错误:“print >> ...”语句中不支持的操作数类型

当我尝试在 Python 3.6 下运行此代码时:

import sys

print >>sys.stderr, 'waiting for a connection'
Run Code Online (Sandbox Code Playgroud)

我明白了TypeError

Traceback (most recent call last):
  File "D:/Users/Chanhc1997/Desktop/test_c.py", line 8, in <module>
    print >>sys.stderr, 'waiting for a connection'
TypeError: unsupported operand type(s) for >>:
'builtin_function_or_method' and 'PseudoOutputFile'.
Did you mean "print(<message>, file=<output_stream>)"?
Run Code Online (Sandbox Code Playgroud)

该代码在 Python 2 中运行良好。这是怎么回事?

python printing python-2.x python-3.x python-3.6

3
推荐指数
1
解决办法
3571
查看次数

标签 统计

printing ×1

python ×1

python-2.x ×1

python-3.6 ×1

python-3.x ×1