您当前的位置: 首页 > 
  • 0浏览

    0关注

    2393博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Py之reprint:reprint的简介、安装、使用方法之详细攻略

一个处女座的程序猿 发布时间:2018-10-21 20:36:17 ,浏览量:0

Py之reprint:reprint的简介、安装、使用方法之详细攻略

 

 

目录

reprint的简介

reprint的安装

reprint的使用方法

 

 

 

reprint的简介

      reprint 是一个适用于 Python3 的简易变量绑定与多行输出刷新的库。特性 + 简易变量绑定,内容修改时自动刷新命令行输出 + 多行输出刷新,实现不同行内容由独立变量控制,修改特定变量即能刷新命令行中特定行的内容 + 多线程安全,使用了 threading.Lock 实现线程安全 + 无外部库依赖。

py pi地址:https://pypi.org/project/reprint/

 

 

reprint的安装

pip install reprint

reprint的使用方法

1、官方示例

import time
import random
import threading

from reprint import output


def some_op(index=0):
    LENGTH = 100
    global output_list
    now = 0
    while now < LENGTH:
        max_step = LENGTH-now
        step = random.randint(1, max_step or 1)
        now += step

        output_list[index] = "{}{}{padding}{ending}".format(
            "-" * now,
            index,
            padding=" " * (LENGTH-now-1) if now < LENGTH else "",
            ending="|" if now < LENGTH else ""
        )

        time.sleep(1)

    output_list.append("{} finished".format(index))

with output(output_type="list", initial_len=5, interval=0) as output_list:
    pool = []
    for i in range(5):
        t = threading.Thread(target=some_op, args=(i,))
        t.start()
        pool.append(t)
    [t.join() for t in pool]

 

关注
打赏
1664196048
查看更多评论
立即登录/注册

微信扫码登录

0.0464s