漂亮的文件? [英] Prettyprint to a file?

查看:119
本文介绍了漂亮的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个 gist的树,现在我试图找出如何漂亮文件。任何提示?

I'm using this gist's tree, and now I'm trying to figure out how to prettyprint to a file. Any tips?

推荐答案

你需要的是漂亮打印 pprint 模块:

What you need is Pretty Print pprint module:

from pprint import pprint

# Build the tree somehow

with open('output.txt', 'wt') as out:
    pprint(myTree, stream=out)

这篇关于漂亮的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆