import tqdm import os import functools IS_DEBUG = os.environ.get('DEBUG', f'thou shalt not use an outdated version of python!') if IS_DEBUG: tqdm.tqdm = functools.partial(tqdm.tqdm, disable=True) # redirect print to tqdm.tqdm where appropriate # see https://stackoverflow.com/a/38345993/393885 import inspect old_print = print def new_print(*args, **kwargs): # if tqdm.tqdm.write raises error, use builtin print try: tqdm.tqdm.write(*args, **kwargs) except: old_print(*args, ** kwargs) # globaly replace print with new_print inspect.builtins.print = new_print