python计时time库函数

 
  1. #TextProBarV3.py

  2. import time

  3. scale = 50    #进度条总长度

  4. print("执行开始".center(scale//2, "-"))

  5. start = time.perf_counter()     #time库的perf_counter方法实现获取系统时间,精确到微秒

  6. for i in range(scale+1):

  7. a = '*' * i

  8. b = '.' * (scale - i)

  9. c = (i/scale)*100

  10. dur = time.perf_counter() - start

  11. print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='') #r回到行首实现单行动态刷新,IDLE会屏蔽/r功能,请在cmd用python命令运行程序

  12. time.sleep(0.1)

  13. print("\n"+"执行结束".center(scale//2,'-'))

 
  1. #TextProBarV1.py

  2. import time

  3. scale = 10

  4. print("------执行开始------")

  5. for i in range(scale+1):

  6. a = '*' * i

  7. b = '.' * (scale - i)

  8. c = (i/scale)*100

  9. print("{:^3.0f}%[{}->{}]".format(c,a,b))

  10. time.sleep(0.1)

  11. print("------执行结束------")

 
  1. #TextProBarV2.py

  2. import time

  3. for i in range(101):

  4. print("\r{:3}%".format(i), end="")

  5. time.sleep(0.1)

 

你可能感兴趣的:(python)