V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
panyanyany
V2EX  ›  Python

[python] 写了个的变量打印工具,类似 [pprint] ,主要是调试的时候用

  •  1
     
  •   panyanyany · 2016-08-26 22:35:22 +08:00 · 2071 次点击
    这是一个创建于 2799 天前的主题,其中的信息可能已经有所发展或是发生改变。

    麻烦大家给点意见,谢谢了!

    Github

    https://github.com/panyanyany/beeprint

    Installation

    pip install beeprint
    

    Examples

    Import beeprint as pp

    from beeprint.printer import beeprint as pp
    

    Short List

    In [2]: alist = [1, 2, 3, 4, 5, 6]
    
    In [3]: pp(alist)
    [1, 2, 3, 4, 5, 6]
    

    Complicated List

    In [4]: clist = [1, [2], {'key': 'val'}]
    
    In [5]: pp(clist)
    [
      1,
      [2],
      {
        'key': 'val',
      },
    ]
    

    Class Instance

    In [6]: class NormalClassNewStyle(object): 
       ...:         def mth():pass
       ...:         static_props = 1
       ...:         lists = []
       ...:         dicts = {}
       ...:         tupl = (1,2)
       ...:     
    
    In [7]: obj = NormalClassNewStyle()
    
    In [8]: pp(obj)
    instance(NormalClassNewStyle):
      dicts: {
      },
      lists: [],
      static_props: 1,
      tupl: (1, 2)
    

    Long Text

    In [27]: long_text_en = "The separation of the sky and the earth took eighteen thousand years-the yang which was light and pure rose to become the sky, and the yin which was heavy and murky (朦胧的) sank to form the earth. Between them was Pangu, who went through nine changes every day, his wisdom greater than that of the sky and his ability greater than that of the earth. Every day the sky rose ten feet higher, the earth became ten feet thicker, and Pangu grew ten feet taller."
    
    In [28]: pp(long_text_en)
    'The separation of the sky and the earth took eighteen thousand years-the yang which was light and pure rose to
     become the sky, and the yin which was heavy and murky (朦胧的) sank to form the earth. Between them was Pangu,
     who went through nine changes every day, his wisdom greater than that of the sky and his ability greater than that
     of the earth. Every day the sky rose ten feet higher, the earth became ten feet thicker, and Pangu grew ten feet
     taller.'
    
    In [30]: long_text_cn = "据民间神话传说古时盘古生在黑暗团中,他不能忍受黑暗,用神斧劈向四方,逐渐使天空高远,大地辽阔。他为不使天地会重新合并,继续施展法术。每当盘古的身体长高一尺,天空就随之增高一尺,经过 1.8 万多年的努力,盘古变成 一位顶天立地的巨人,而天空也升得高不可及,大地也变得厚实无比。盘古生前完成开天辟地的伟大业绩,死后永远留给后人无穷 无尽的宝藏,成为中华民族崇拜的英雄。""
    
    In [31]: pp(long_text_cn)
    '据民间神话传说古时盘古生在黑暗团中,他不能忍受黑暗,用神斧劈向四方,逐渐使天空高远,大地辽阔。他为不使天地会重新合
     并,继续施展法术。每当盘古的身体长高一尺,天空就随之增高一尺,经过 1.8 万多年的努力,盘古变成一位顶天立地的巨人,而
     天空也升得高不可及,大地也变得厚实无比。盘古生前完成开天辟地的伟大业绩,死后永远留给后人无穷无尽的宝藏,成为中华民
     族崇拜的英雄。'
    

    Long Text in Dict

    In [33]: d = {'en': long_text_en, 'cn': long_text_cn}
    
    In [34]: pp(d)
    {
      'en': 'The separation of the sky and the earth took eighteen thousand years-the yang which was light and pure
             rose to become the sky, and the yin which was heavy and murky (朦胧的) sank to form the earth. Between
             them was Pangu, who went through nine changes every day, his wisdom greater than that of the sky and his
             ability greater than that of the earth. Every day the sky rose ten feet higher, the earth became ten feet
             thicker, and Pangu grew ten feet taller.',
      'cn': '据民间神话传说古时盘古生在黑暗团中,他不能忍受黑暗,用神斧劈向四方,逐渐使天空高远,大地辽阔。他为不使天地
             会重新合并,继续施展法术。每当盘古的身体长高一尺,天空就随之增高一尺,经过 1.8 万多年的努力,盘古变成一位顶
             天立地的巨人,而天空也升得高不可及,大地也变得厚实无比。盘古生前完成开天辟地的伟大业绩,死后永远留给后人无
             穷无尽的宝藏,成为中华民族崇拜的英雄。',
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1475 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:19 · PVG 01:19 · LAX 10:19 · JFK 13:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.