Last active
March 4, 2021 22:06
-
-
Save justinhchae/a2efee420330a985286e7b88fd049ce5 to your computer and use it in GitHub Desktop.
A do nothing functio to demonstrate a function call to a function that does a progress bar with tqdm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# solution reference: | |
# https://stackoverflow.com/questions/41707229/tqdm-printing-to-newline | |
def fc(x, param): | |
# inject some waiting to see progress unfold | |
time.sleep(1) | |
# set up pbar | |
pbar = tqdm(x.items(), desc='Exp:', position=0) | |
# init a variable for output | |
yhat = 0 | |
name = x.keys() | |
# loop through objects | |
for i,v in pbar: | |
time.sleep(1) | |
for ii in v: | |
# a contrived example of some computation | |
error = np.exp(ii) | |
# set up the pbar so that we don't get a new line each time | |
pbar.set_description('Exp {}, value {:.2f}'.format(i, error)) | |
# update the pbar during the loop | |
pbar.refresh() | |
# inject some wait time | |
time.sleep(1) | |
# just adding here but could be anything | |
yhat+=ii | |
return yhat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment