这个打印语法是什么? (打印右移)
查看 pstats 的源代码 我看到以下语法
print >> self.stream, "in %.3f seconds" % self.total_tt
print >> self.stream
:这是语法吗,它是如何调用的以及如何使用它?我以前从未见过它,也没有在我读过的任何 Python 书籍/教程中见过它。
Looking at the source code of pstats I see this syntax:
print >> self.stream, "in %.3f seconds" % self.total_tt
print >> self.stream
What is this syntax, how is it called and how to use it? I have never seen it before, nor seen it in any of the Python books/tutorials I have read.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您指的是
>>
,那么这是 Python 2.x 语法,用于使用print
sys.stdout 以外的文件>。它在 Python 文档 6.6 中定义。 print 语句 至少从 Python 2.5 就已经存在了(我认为更早)。此语法已替换为 Python 3.0 中
print
函数的file
kwarg。If you mean the
>>
, that's the Python 2.x syntax for writing to a file-like other thansys.stdout
withprint
. It's defined in the Python docs, 6.6. The print statement and has been around since at least Python 2.5 (and I think earlier).This syntax has been replaced with a
file
kwarg to theprint
function in Python 3.0.它是 print 语句的扩展形式,它将输出重定向到紧随其后的类似文件的对象。请参阅 Python 文档。
It's the extended form of the print statement which redirects the output to the file-like object immediately following it. See the Python docs.