>>运算符在python中做什么?

Zac*_*h P 2 python

我在一个项目中找到了这个代码,我不知道它的>>作用.有人有解释吗?

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)
Run Code Online (Sandbox Code Playgroud)

我知道这段代码从模块中的其他文件和对象获取信息,我知道代码的整体运作方式.只有这print >>让我感到困惑.当此模块安装在没有写访问权限的目录中时,将显示该消息Could not cache....整个文件都在这里,但我怀疑它会有所帮助.

jam*_*lak 6

>> 打印到像对象这样的文件

print还具有扩展形式,由上述语法的第二部分定义.这种形式有时被称为" print雪佛龙".在这种形式中,>>必须在"文件类"对象之后的第一个表达式,特别是具有上述write()方法的对象.使用此扩展表单,后续表达式将打印到此文件对象.如果第一个表达式求值为None,则sys.stdout用作输出文件.

print statement

在这种情况下,它会打印一条错误消息 stderr