tree_output:使用命令行界面简化树输出构建的 Python 库

  • w9_234741
    了解作者
  • 8.8KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-16 01:30
    上传日期
树输出 使用命令行界面简化树输出构建的 Python 库。 支持的输出格式选项有: json ASCII码 安西 空值 例子 tree_output = HierarchicalOutput . factory ( 'ansi' ) import colorama tree_output . emit ( 'foo' ) tree_output . add_level () tree_output . emit ( 'foO' ) tree_output . add_level () tree_output . emit ( 'bar' ) tree_output . add_level () for num in range ( 10 ): tree_output . emit ( num ) tree_output . emit ( 10 , closed = Tru
tree_output-master.zip
  • tree_output-master
  • .travis.yml
    167B
  • tree_output
  • log_handler.py
    958B
  • houtput.py
    7.7KB
  • __init__.py
    40B
  • tests
  • test_logging.py
    1.5KB
  • mock
  • expected_ansi
    1.4KB
  • test_tree_output.py
    2.8KB
  • LICENSE
    1.1KB
  • setup.py
    1.4KB
  • .gitignore
    544B
  • README.md
    2.4KB
内容介绍
tree_output =========== [![Build Status](https://travis-ci.org/ewiger/tree_output.svg?branch=master)](https://travis-ci.org/ewiger/tree_output) Python library to simplify building of tree output with command-line interfaces. Supported output format options are: - json - ascii - ansi - null examples -------- ```python tree_output = HierarchicalOutput.factory('ansi') import colorama tree_output.emit('foo') tree_output.add_level() tree_output.emit('foO') tree_output.add_level() tree_output.emit('bar') tree_output.add_level() for num in range(10): tree_output.emit(num) tree_output.emit(10, closed=True) tree_output.remove_level() tree_output.emit('baz', closed=True) tree_output.emit('foo2') ``` this will draw a colorful ANSI output like this ``` . ├── foo │   ├── foO │   │   ├── bar │   │   │   ├── 0 │   │   │   ├── 1 │   │   │   ├── 2 │   │   │   ├── 3 │   │   │   ├── 4 │   │   │   ├── 5 │   │   │   ├── 6 │   │   │   ├── 7 │   │   │   ├── 8 │   │   │   ├── 9 │   │   │   └── 10 │   └── baz ├── foo2 ``` logging ------- Another option is to integrate with logging and pass hierarchical meta instructions via optional **extra** argument, e.g. ```python houtput = HierarchicalOutput.factory(format='json') #houtput = HierarchicalOutput.factory(format='ansi') handler = HierarchicalOutputHandler(houtput=houtput) logger = logging.getLogger('foo') logging.root.addHandler(handler) # Emission. logger.info('foo') logger.info('bar', extra={'add_hlevel': True}) logger.info('foo2') logger.info('bar', extra={'add_hlevel': True}) logger.info('foo2') logger.info('Numbers', extra={'add_hlevel': True}) for num in range(10): logger.warn(num) logger.warn('end of numbers', extra={'hclosed': True}) logger.debug('level up', extra={'remove_hclosed': True}) ``` produces ```json ["foo", [ "bar", "foo2", [" bar", "foo2", [ "Numbers", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "end of numbers" ], "level up"] ] ] ``` tests ----- For tests we use *nose*, i.e. usage would be: ```bash cd tests && nosetests ```
评论
    相关推荐