Pytube:如何为函数添加参数 progress_Check

Pytube : How to add the parameters for function progress_Check

def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None):
    global file_size
    #Gets the percentage of the file that has been downloaded.
    percent = (100*(file_size-remaining))/file_size
    print("{:00.0f}% downloaded".format(percent))

调用上述函数返回下载百分比时

yt = YouTube(link,on_progress_callback=progress_Check)

但是我得到了一个错误,比如不能减去整数和 None,那么得到它们的函数 parameters/how 是什么?

有什么想法吗??

progress_Check 只需要 3 个参数:streamchunkremaining

因为只需要3个参数,第4个没有赋值给任何东西,所以remaining会被设置为None,会导致计算出错

您也不需要将每个参数的默认值设置为 None,因为它们无论如何都会被覆盖

固定代码如下:

def progress_Check(stream, chunk, remaining):
    global file_size
    #Gets the percentage of the file that has been downloaded.
    percent = (100 * (file_size - remaining)) / file_size
    print("{:00.0f}% downloaded".format(percent))