Node.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def write_json(self, data, pretty=True):
        """
        Writes a python object as JSON to disk. Files are always written as UTF8 as per the JSON standard::

            def build(bld):
                bld.path.find_node('xyz.json').write_json(199)

        :type  data: object
        :param data: The data to write to disk
        :type  pretty: boolean
        :param pretty: Determines if the JSON will be nicely space separated
        """
        import json # Python 2.6 and up
        indent = 2
        separators = (',', ': ')
        sort_keys = pretty
        newline = os.linesep
        if not pretty:
            indent = None
            separators = (',', ':')
            newline = ''
        output = json.dumps(data, indent=indent, separators=separators, sort_keys=sort_keys) + newline
        self.write(output, encoding='utf-8')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号