I want to change a string on the console while it's outputted.
For example I can take a string such as "test"
and output each character on the console with this:
for c in "test":
sys.stdout.write(c)
time.sleep(1)
#<= t
#<= te
#<= tes
etc..
But what if I wanted to take that output and change it while it was on the screen? For example, what if I wanted to capitalize each letter in the string while something runs in the background (kinda like a progress bar). So it would end up looking like this:
#<= Test
#<= tEst
#<= teSt
#<= tesT
Over and over again until whatever I'm downloading or running is finished. How can I go about changing the string itself on the console?
Seeing how this was duplicated I'll rephrase it.
I want to take the string that I have test
and use (probably) stdout.flush()
or something along those lines and capitalize each letter of that string while something runs in the background, so for example:
def download():
# download something using requests(stream=True)
while chunk_downloading:
sys.stdout.write("test")
# do something here to where it will run through the string and capitalize each letter
sys.stdout.flush()
The output of this should look something along these lines (on one singular line):
test -> Test -> tEst -> teSt -> tesT -> test -> etc..