[英]Python unsupported operand type(s) for >>
I've never used such code with streams: 我从未在流中使用过这样的代码:
print >>self._stream, indentation + line
Would like to look at the docs. 想看一下文档。 Google wasn't good at searching ">>".
Google并不擅长搜索“ >>”。
The question is - how to write it in Python 3? 问题是-如何在Python 3中编写它?
It causes an error: 它导致一个错误:
Python unsupported operand type(s) for >>
By default (in function) stream is sys.stdout
默认情况下(在函数中)流是
sys.stdout
The >>
syntax prints the string to the given stream instead of stdout. >>
语法将字符串打印到给定的流,而不是标准输出。
The equivalent in python 3 is the file
keyword argument on the print
function. python 3中的等效项是
print
函数上的file
关键字参数。
print('my text here', file=self._stream)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.