首页 > 编程知识 正文

python文本进度条import,文本进度条python

时间:2023-05-04 14:29:05 阅读:11812 作者:4614

whencopyinglargefilesusingshutil.copy (,yougetnoindicationofhowtheoperationisprogressing .

ihaveputtogethersomethingthatworks-itusesasimpleprogressbarclass (whichsimplereturnsasimpleasciiprogressssbar,as a string ), andaloopofopen(.read ) ) and .write ) ) todotheactualcopying.itdisplaystheprogressbarusingsys.stdout.write () )

youcanseethecode(incontext ) on github here

isthereanybuilt-inmodulethatwilldothisbetter? isthereanyimprovementsthatcanbemadetothiscode?

Two things:

iwouldmakethedefaultblocksizealotlargerthan 512.iwouldstartwith 16384 andperhapsmore。

For modularity,itmightbebettertohavethecopy _ with _ progfunctionnotoutputtheprogressbaritself,butcallacallbackfunctionso

Perhaps something like this:

defcopy_with_Prog(src,dest,callback=None ) :

while True:

#复制loop stuff

if callback:

呼叫后退(销售点,总) )。

Prog=Progressbar(…)

复制_ with _ Prog (src,dest,lambda pos,total:Prog.update ) pos,total )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。