当前位置: 首页>>代码示例>>Python>>正文


Python Log.beautify_json方法代码示例

本文整理汇总了Python中tools.log.Log.beautify_json方法的典型用法代码示例。如果您正苦于以下问题:Python Log.beautify_json方法的具体用法?Python Log.beautify_json怎么用?Python Log.beautify_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tools.log.Log的用法示例。


在下文中一共展示了Log.beautify_json方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_html_report

# 需要导入模块: from tools.log import Log [as 别名]
# 或者: from tools.log.Log import beautify_json [as 别名]
 def generate_html_report(self, report_in_js=True):
     self.generate_report_path()
     reportjs = self.report_path + '/' + 'report.js'
     reporttemplate = self.html_path + '/' + 'report.html'
     reporthtml = self.report_path + '/' + self.dict_all["project"]["name"] + '.html'
     if report_in_js:
         shutil.copy(reporttemplate, reporthtml)
         with open(reportjs, 'w') as f:
             try:
                 d = Log.beautify_json(self.dict_all).encode('utf8').decode('utf8')
                 f.writelines(["report = ", "\n", d, ";", "\n"])
             except UnicodeDecodeError as e:
                 print(e)
     else:
         reporthtml = self.report_path + '/' + self.dict_all["project"]["name"] + '_report.html'
         with open(reporttemplate, 'r') as src, open(reporthtml, 'w') as dst:
             for line in src:
                 if "<script" in line and "src" in line and "report.js" in line:
                     d = Log.beautify_json(self.dict_all)
                     dst.writelines(["<script type='text/javascript' charset='utf-8'>", "\n"])
                     dst.writelines(["var report = ", "\n"])
                     dst.writelines([d.encode("utf8").decode("utf8"), ";", "\n"])
                     dst.writelines(["</script>", "\n"])
                 else:
                     dst.write(line)
     pass
开发者ID:alpha-jacobshih,项目名称:pyjects,代码行数:28,代码来源:efs.py

示例2: write_to_file

# 需要导入模块: from tools.log import Log [as 别名]
# 或者: from tools.log.Log import beautify_json [as 别名]
def write_to_file(thepath, thefile, content, append=False):
    if not content:
        content = {}
    data = Log.beautify_json(content) if type(content) is not str else content

    if not os.path.exists(thepath):
        os.makedirs(thepath)
    try:
        filepath = "%s/%s" % (thepath, thefile)
        file_open_mode = "a" if append else "w"
        with codecs.open(filepath, file_open_mode, "utf-8-sig") as f:
            f.write(unicode(data, "utf-8"))
            f.write("\r\n")
    except UnicodeDecodeError as e:
        print "UnicodeDecodeError: %s" % e
    except IOError as e:
        print "IOError: %s" % e
    pass
开发者ID:jacobshih,项目名称:pyzzle,代码行数:20,代码来源:pyren.py


注:本文中的tools.log.Log.beautify_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。