I apologize if this question has been answered a million times but Ive searched and tried everything to no avail. I have a simple program I created at work that copies truck stop locations to the clipboard to be pasted in emails and work orders. The shop locations are in a dictionary and use the location number as the key. It prints a list of locations with their location codes and asks you to type the number and it copies it to the clipboard. The program works great and has made life much easier, but Id like to improve one thing. The main code is in a while loop so I can leave it running and use it as needed (location list showing keys is only printed once unless you type 'list'). Problem is that I would like it to overwrite every iteration rather than print 'Type location number or 'list'', then 'location info copied to clipboard' over and over. I'd like it to display these messages and start fresh with every iteration. Ive tried sys.stdout, print(flush) and every other solution I can find. Any help would be greatly appreciated. Below is the while loop part of the program, I didn't include the dictionary named TEXT or the list of location keys as they are VERY long.
while True:
clipboard = input("Type location number or 'list': ")
if clipboard.lower() == 'list':
print(locations)
elif clipboard.isalpha() == True or clipboard.isdecimal() == False:
print()
print('Command not found')
print()
elif int(clipboard) in TEXT:
pyperclip.copy(TEXT[int(clipboard)])
print()
print('Location info copied to clipboard')
print()
else:
print()
print('Location not found')
print()