为面向用户的打印语句提供方便的格式、颜色和实用程序。

display-session的Python项目详细描述


display session是麻省理工学院授权的python包,它为python的内置print语句提供了简单的ansi格式和实用程序。

这个项目源于想要更好的外观、更多的信息和更吸引人的命令行界面。

有三个功能面向用户:

  1. 页眉-打印提供的消息,所有其他空间作为提供的justify_char。作为一种简单的方式来沟通日志中的不同部分。
  2. alert-将数字参数(-1,0,1)映射到bad,neutral,good的简单打印语句。作为沟通信息情感的简单方法。
  3. 报表-最复杂的打印报表。使用署名处理所有邮件,如果提供,则在打印时运行所有提供的函数。用作命令行的一种平视显示。见下面的例子。

简单比较和示例:

>>>print('This is how the builtin print function works')
This is how the builtin print function works

显示会话最简单、最引人注目的用例:

>>>from display_session import DisplaySession
>>>display = DisplaySession('This is a byline')
>>>display.report('The byline proceeds any text input here')

# hard to show with markdown, but byline is also separately ANSI colored.
This is a byline  : The byline proceeds any text input here

更复杂的示例:

>>>import datetime as dt
>>>import psutil

>>>from display_session import DisplaySession
>>>user = 'John'

>>>display = DisplaySession(byline='P R O G R A M - {}'.format(user),
                            byline_action=[dt.datetime.now, psutil.cpu_percent]
                            )
>>>display.report('User successfully logged in')
 P R O G R A M - John  // 2018-09-19 21:55:29.115387 // 9.1: User successfully logged in.
>>>display.report('User successfully logged out')
 P R O G R A M - John  // 2018-09-19 21:56:14.560489 // 7.8: User successfully logged out.

其他功能:

>>># lets signify to our users that we are entering a new section
>>>display.header('BEGINNING LEVEL 2', align='right')
______________________________________________________________________ BEGINNING LEVEL 2

>>># lets communicate by leveraging ANSI colors - our second arg maps to them in the method.
>>>display.alert('This message is good, so it should have a green color', 1)
This message is good, so it should have a green color
>>>
>>>display.alert('This message is bad, so it should have a red color', -1)
This message is bad, so it should have a red color

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
junit有没有办法在Java中重新初始化静态类?   在浏览器中点击应用程序时java Play框架挂起   文件Java错误中的NullPointerException   使用Java中的SNMP查找网络中计算机的登录名   java包装服务器引导程序已弃用,有什么替代方案?   当客户在等待理发时,java信号量值是否存在问题?   java如何使用JavaMail仅下载特定类型的附件   如何在java中将十进制转换为十六进制   java Slick2D粒子系统不会生成粒子   java检测更改事件来自何处   将Java集合类型参数类设置为数组   java如何从eclipse导出为可运行JAR文件?   java EntityManager对象未注入Glassfish和Spring   swing从actionPerformed和actionListener Java返回字符串   java在给定另一个等价键对象的情况下获取映射项的当前键   无论输入如何,java网络都会产生相同的输出