Skip to main content

format_print

一个用于格式化输出的库,主要功能包括多行输出刷新、全半角字符混合对齐、秒数及字节大小格式化等。

pip

pip install format_print

主要功能简介

  • Unicode_len: 获取全半角混合字符串的长度

    半角字符长度为1,全角字符长度为2,以此计算总长度。

  • Rehuman: 数字格式化

    将整数或浮点数转化为携带单位的字符串,目前包括:时长、字节,允许指定进制、单位、格式等。

  • Respacing: 全半角混合字符串对齐

    为同时包含全角和半角的字符串设置对齐,全角字符长度视为半角字符的2倍。

  • Rows_print: 多行输出

    主要用于多行字符串的刷新,可以指定输出起始行次、对齐方式

简易示例

from format_print import Unicode_len, Rehuman, Respacing, Rows_print
import time

# Unicode_len
length = Unicode_len('该文本的长度:16').get_len()
print(length) # 16

# Rehuman
print(Rehuman(100000).from_size()) # 97.66KB
print(Rehuman(500).from_seconds()) # 00h08m20s
print('\n')

# Rows_print
Rows_print(
    '第1行\n这里是第2行',
    '^',
).print_str()
'''
   第1行
这里是第2行
'''

# Respacing
for i in range(37):
    print(
        Respacing(
            "[",
            ("=" * min(i, 12), 12, "<"),
            "进度:{:>3.2f}%".format(i / 36 * 100),
            ("=" * (i - 24), 12, "<"),
            "]",
            space = '_'
        ).get_str(),
        end = '\r'
    )
    time.sleep(0.3)
print()
'''
生成进度条
[============进度:50.00%____________]
'''

Metadata

Release files for format-print 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for format-print 1.0
File Size Uploaded
format_print-1.0.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for format-print 1.0
File Interpreter ABI Platform
format_print-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / format_print-1.0.tar.gz

Download URL format_print-1.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
da4867840b12b910160f6df7009ccc28479ad37d1d73d2430eb34c1e541a55cc
BLAKE2b-256 checksum
How to use checksums
bc23ae6fc135883e8be1868e47c3aca84682b2ea9d7924371c5bdaca90089983
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.6

Release files / format_print-1.0-py3-none-any.whl

Download URL format_print-1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4aa441f206fef284b6d78726cc8a878fd9b0e9f37ea88f37be35efafab974a20
BLAKE2b-256 checksum
How to use checksums
87529693d33ffaf4ff5e58b151d5b23251b49ec9e445af436803e9e16858cde0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page