import time #only to make delay between operations for demonstration purposes
class pBar():
def __init__ (self, vmax, length=25, bchar=u"\u25A0"):
self.vmax = vmax #vmax - total number of items to iterate
self.bchar = bchar #symbol to use as bar mark
self.length = length #lenght - bar length in characters
self.val = 0
self.cur = 0
def incr (self):
self.val += 1
self.cur = int((self.val/self.vmax)*self.length)
print('[' + self.bchar*self.cur + ' '*(self.length-self.cur) + ']' + ' '*(4-len(str(int(self.val*100/self.vmax)))) + str(int(self.val*100/self.vmax)), end='%\r')
if self.val == self.vmax :
print('\n') # to make output less messy
mybar = pBar(56)
#demo:
i = 0
while i < 56 :
mybar.incr()
time.sleep(0.2)
i += 1
我是否正确理解文件应该直接从脚本发送?如果是这样,那么就有 requests 库,并且代码示例已经在 SO: Send file using POST from a Python script 但是,在这种情况下不太可能显示进度 - 为此你需要击败将文件分成块并创建一个类: Python 请求的进度 post,并且已经使用块工作至于显示进度本身,那么你可以做这样的事情(我为某个项目着急做了,但你可以想象一下出去: