使用python的文本接口的人性化输出

humanfriendl的Python项目详细描述


https://travis-ci.org/xolox/python-humanfriendly.svg?branch=masterhttps://coveralls.io/repos/xolox/python-humanfriendly/badge.png?branch=master

可以使用humanfriendly包中的函数和类 文本界面更加用户友好。一些示例功能:

  • 解析和格式化中的数字、文件大小、路径名和时间跨度 简单,人性化的格式。
  • 易于使用计时器进行长时间运行操作,人性化 结果时间跨度的格式。
  • 通过键入 选项的编号或选项的唯一子字符串。
  • 终端交互,包括文本样式(ANSI转义序列),用户 友好的使用消息呈现和查询终端 大小。

humanfriendly包目前在python 2.6、2.7、3.4、3.5上进行测试, Linux和MacOSX上的3.6、3.7和Pypy(2.7)。 也可以支撑窗户,你可能会遇到一些粗糙的边缘。

Getting started

开始使用humanfriendly包非常简单:

>>> import humanfriendly
>>> user_input = raw_input("Enter a readable file size: ")
Enter a readable file size: 16G
>>> num_bytes = humanfriendly.parse_size(user_input)
>>> print num_bytes
16000000000
>>> print "You entered:", humanfriendly.format_size(num_bytes)
You entered: 16 GB
>>> print "You entered:", humanfriendly.format_size(num_bytes, binary=True)
You entered: 14.9 GiB

Command line

用法:humanfriendly [OPTIONS]

命令上人性化的输入/输出(文本格式) 基于同名python包的行。

支持的选项:

OptionDescription
^{tt1}$, ^{tt2}$Execute an external command (given as the positional arguments) and render a spinner and timer while the command is running. The exit status of the command is propagated.
^{tt3}$Read tabular data from standard input (each line is a row and each whitespace separated field is a column), format the data as a table and print the resulting table to standard output. See also the ^{tt4}$ option.
^{tt5}$, ^{tt6}$Change the delimiter used by ^{tt3}$ to ^{tt8}$ (a string). By default all whitespace is treated as a delimiter.
^{tt9}$, ^{tt10}$Convert a length count (given as the integer or float ^{tt11}$) into a human readable string and print that string to standard output.
^{tt12}$, ^{tt13}$Format a number (given as the integer or floating point number ^{tt8}$) with thousands separators and two decimal places (if needed) and print the formatted number to standard output.
^{tt15}$, ^{tt16}$Convert a byte count (given as the integer ^{tt17}$) into a human readable string and print that string to standard output.
^{tt18}$, ^{tt19}$Change the output of ^{tt15}$, ^{tt21}$ to use binary multiples of bytes (base-2) instead of the default decimal multiples of bytes (base-10).
^{tt22}$, ^{tt23}$Convert a number of seconds (given as the floating point number ^{tt24}$) into a human readable timespan and print that string to standard output.
^{tt25}$Parse a human readable length (given as the string ^{tt8}$) and print the number of metres to standard output.
^{tt27}$Parse a human readable data size (given as the string ^{tt8}$) and print the number of bytes to standard output.
^{tt29}$Demonstrate changing the style and color of the terminal font using ANSI escape sequences.
^{tt30}$, ^{tt31}$Show this message and exit.

A note about size units

当我最初发布humanfriendly包时,我使用了二进制 字节的倍数(2的幂)。有人多次指出 是一个糟糕的选择(参见问题#4和拉取请求#8#9),因此 新的默认值变为字节的十进制倍数(10的幂):

UnitBinary valueDecimal value
KB10241000
MB10485761000000
GB10737418241000000000
TB10995116277761000000000000
etc

使用二进制字节倍数的选项仍然是通过传递关键字 参数binary=True指向format_size()parse_size()函数。

Contact

最新版本的humanfriendly可在PyPIGitHub上找到。这个 文档位于Read the Docs上,并包含一个changelog。对于Bug 报告请在GitHub上创建问题。如果你有问题,建议, 等等,请随时给我发一封电子邮件peter@peterodding.com

License

此软件是根据MIT license授权的。

版权所有©2018彼得·奥丁。

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

推荐PyPI第三方库


热门话题
Java类之间并发性不一致的HashMap   插件如何在JavaSwing中使用UIManager和Classloader从外部jar安装外观?   java JasperReports:找不到子报表   在项目中找不到java生成的Javadoc文件   java BigDecimal。multiply()和divide()方法返回十六进制数。为什么?   java统计出现次数并从字符串中删除重复项   调用运算符时发生java NullPointerException   Spring和Hibernate之间的java配置错误   JavaZK将用户重定向回上一页   Javasocket为传出连接指定特定的网络接口   如果拖动到某个区域外,java Make按钮操作将被取消   如何在Eclipse for selenium 3.141.59中添加Java文档链接   java从匹配条件的数组中获取所有索引   docker未连接到RemoteWebDriver的java Gitlab ci selenium测试   java重写run方法   utf 8如何使用java解码UTF8编码的字符串?   java如何从eclipse调试部署在tomcat上的web应用程序?   将字母字符与前面没有百分号的Java正则表达式匹配