This isn't really a question, but improvement of code, and may help others out either way since I already figured a simple workaround.
I was wondering how I can give the progress bar from the module "tqdm" the total input, instead of the increments as the 'manual update' function tqdm.update() requires.
So the main reason I needed to know this is for a YouTube downloader from the module "pytube" to show the download progress. When I call the .download() function, as far as I'm concerned, it will run a while loop by fetching the data and calls a custom "progressFunction", with the remaining number of bytes as input. With a global variable equal to the size of the file, I can calculate the total progress, size of file minus remaining, of the download, thus allowing logging of the progress. Now in this case it would've been nice if the progress bar from tqdm accepted this total progress but again, the .update() only accepts an increment in number of iterations.
So I did some searching in the _tqdm.py code and found out that the previous iteration variable is stored in self.n. So the increment can be calculated like this: inc = new_iter - pbar.n, where pbar is a tqdm progress bar instance.
Here's a sample code of a similar function to illustrate it. It has a while loop function that returns nothing, but gives input to another function. Copy and paste it if you want, it will show a simple progress bar from 0 to 100.
import time
from tqdm import tqdm
def functExec(a):
global pbar
a_prev = pbar.n
step_tqdm = a-a_prev
pbar.update(step_tqdm)
def functLoop(functExec,range,step):
a = 0
while a<range:
a += step
functExec(a)
time.sleep(0.02)
N = 100
step = 1
pbar = tqdm(total=N/step)
functLoop(functExec,range=N,step=step)
pbar.close()
So as you can see pbar is a tqdm progress bar instance. This gets initialised before the while loop is called. In the function "functLoop" variable "a" is looped from 0 to 100 with a 'while loop', and calls "functExec", which updates the progress bar. You can notice that pbar.n is called, and is the value of the iteration that pbar has before it's updated. To get the increment simply a-pbar.n is called, and with this pbar is updated with the .update() function.
TO CONCLUDE: yes it works like I wanted, but I'm wondering if I can just use the variable "a" to directly assign the progress bar to the total progress, instead of using the step first.
Still hope it helped out some of you, was searching for over 4 hours since I couldn't find how to do this on the web :)
EDIT: TLDR: So in short, let's say you want to iterate from 0 to 100 and document the progress with tqdm, but in the case where you can only get the current iteration value or total progress. I managed to show the progress with this code, but was just wondering if there's a built-in function for it in the "tqdm" module. The current source code only allows to incrementally change the progress bar. It made sense there has to be such a function because you initialize the tqdm object's size with the "total" parameter, and can easily calculate the progress with the current total progress directly.