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 )