I want to print some variables to a file in a custom table format and have the ability to add to the table without adding the header again and keeping previous information. Here's my code:
import time as r
data = r.strftime("%d %m %Y %I %M")
with open('myfile.txt','a') as f:
f.write(data + '\n')
Here's the output in the text file:
01 07 2022 01 19
Now here's the output I want:
_________________________________
|Day |Month |Year |Hour |Minute |
|-------------------------------|
|01 |07 |2022 |01 |19 |
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|
And I want to have the ability that if I run the file again that it would add the new output it would look something like this:
_________________________________
|Day |Month |Year |Hour |Minute |
|-------------------------------|
|01 |07 |2022 |01 |19 |
|===============================|
|01 |07 |2022 |02 |10 |
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|
I know this is an absurd post but does anyone know how? Thanks.