【发布时间】:2016-02-20 21:54:30
【问题描述】:
我在一个项目中找到了这段代码,我不知道>> 是做什么的。有人解释一下吗?
def save(self, fpath=None):
"""
Save the JSON data to fpath. This is done automatically if the
game is over.
"""
if fpath is None:
fpath = _jsonf % self.eid
try:
print >> gzip.open(fpath, 'w+'), self.rawData,
except IOError:
print >> sys.stderr, "Could not cache JSON data. Please " \
"make '%s' writable." \
% os.path.dirname(fpath)
我知道这段代码正在从模块中的其他文件和对象中获取信息,并且我知道代码的整体工作方式。只有print >> 让我感到困惑。当这个模块安装在一个没有写访问权限的目录中时,会出现消息Could not cache...。整个文件位于here,但我怀疑它是否会有所帮助。
【问题讨论】:
-
这个问题不是引用问题 “Python 如何简单地将 print 的输出重定向到 TXT 文件,并为每个重定向创建一个新行”。在引用的问题中,“>>”运算符用作解决方案的一部分,但未详细解释其使用。事实上,我首先找到了引用的问题,因为它没有回答我关于“>>”运算符究竟做什么的问题,所以我进一步搜索并找到了这个问题。
标签: python