The variable names in
change_char_atare terrible.sfor the string,chfor the char?ifor the start?jfor the end.Seriously just write out names.
def change_char_at(string: str, change: str, start: int, end: int = None): return string[:start] + change + string[end or start+1:]Your code isn't fully typed:
change_char_athas no return type.endinchange_char_atandwaitinloader_with_waitare assumed to beOptionalbut not specified to be optional.loaderandloader_with_waithave no return types should they beNoneorNoReturn?
The functionallity of
change_char_atcan be eclipsed by the format mini-language.You have a standard structure where the bar is surrounded by
[]and filled with the contents.bar = '[{}]'The content of your bar is left aligned by width.
bar = '[{: <{width}}]'Each iteration you increase the contents is increasedleft hand space by 1 equals.
bar.format('='' ' * (i + '=' * bar_width), width=width)
bar_widthdoesn't actually change the size of the bar.I would prefer the progress bar to be a generator function or list, so the rest of your code is simpler.
import itertools
def progress_bar(width: int = 20, bar_width: int = 3):
bar = f'[{{: <{width}}}]'
for i in itertools.chain(
range(0, width - bar_width + 1),
reversed(range(0, width - bar_width)),
):
yield bar.format('='' ' * i + '=' * bar_width)