#coding=utf-8
import threading
import os,sys
import urllib.request as ur
#顯示調用函數
def jindu(a,b,size):
os.system('cls')
per=100*a*b/size
per=round(per, 2)
if per>100:
per=100
sys.stdout.write('下載進度:{0}%\r'.format(per))
sys.stdout.flush()
#繼承類多線程
class Doal(threading.Thread):
def __init__(self,a,b):
# 繼承類多線程
threading.Thread.__init__(self)
self.__path=a
self.__name=b
def run(self):
#開啟實時顯示
ur.urlretrieve(self.__path,self.__name,jindu)
if __name__ == '__main__':
#下載地址
urls = 'http://dubapkg.cmcmcdn.com/duba/166/kinst_166_f28_k1541.exe'
#名稱
name=urls.split('/')[-1]
#創建文件夾
if not os.path.exists('code'):
os.mkdir('code')
#路徑名稱鏈接
filepath = os.path.join('code',name)
#實例
p=Doal(urls,filepath)
#線程開啟
p.start()