I am trying to write some code which will overwrite its previous output e.g. the original output is "1" but the "1" is replaced with a "2". This makes it look as though the "1" had never been outputted in the first place.
I have a list of lists called board, I convert this list into a multi-line string using this code:
rendered_board = ""
for y in range(board_height):
for x in range(board_width):
rendered_board += board[y][x]
rendered_board += "\n"
I get the string I want, However, I want to be able to update this string with a new one and have it replace the old.
Example output :
+-------+ +-------+
| | *gets replaced by* | |
| | -------------------> | * |
| | | |
+-------+ +-------+
Currently I have been trying to do this by using end="\r"
e.g.
print(rendered_board, end="\r")
update_board()
print(rendered_board, end="\r")
This has resulted in this output:
+-------+
| |
| |
| |
+-------+
+-------+
| |
| * |
| |
+-------+