I am trying to make a fake boot sequence in Python, and one of the elements is a progress bar. The progress bar should stay on one line, instead of repetitively printing over multiple lines. After some time, I had created this code:
from time import sleep
import random
def progressbar(title, length):
add = 0
strlength = len(title) + 3
barlength = '['
for i in range(length - 1):
barlength = barlength + '.'
barlength = barlength + ']'
progress = title + ': ' + barlength
for i in range(length):
print(progress, end='\r')
append = add + strlength
progress = list(progress)
progress[append] = '#'
progress = str(''.join(progress))
sleep(random.uniform(0.2, 1.0))
add = add + 1
print("Username: TestUserABC, Password: password1")
sleep(1)
print('---[STARTING BOOT SEQUENCE]---')
print(':-Welcome to GMOS (Generic Movie Operating System)-:')
progressbar('Checking Filesystem', 10)
However, instead of overwriting one line, it outputs this:
Username: TestUserABC, Password: password1
---[STARTING BOOT SEQUENCE]---
:-Welcome to GMOS (Generic Movie Operating System)-:
Checking Filesystem: [.........]Checking Filesystem: [#........]Checking Filesystem:
[##.......]Checking Filesystem: [###......]Checking Filesystem: [####.....]Checking Filesystem:
[#####....]Checking Filesystem: [######...]Checking Filesystem: [#######..]Checking Filesystem:
[########.]Checking Filesystem: [#########]
I would appreciate any help, as I have no idea what could have caused this. For clarity, I am on Windows 10, just in case the string... things are different between OSs, which I doubt for this kind of thing. (Can somebody tell me what things like \n or \r are called?)