I am sorry for re-asking this but I made the mistake of not providing enough detail. I want to align string and adjust spacing in a column I asked this question.
Here: How to align strings in columns?
But I was not able to apply it to my detailed code which was my mistake for not providing.
My code:
import time
seperator='|'+'-'*33+'|\n'
seperator2='|'+'='*33+'|\n'
end = '|'+'^'*33+'|'
t=['Tuesday','July','2022','03','06']
try:
with open('time.txt','r') as f:
content = f.readlines()
except:
with open('time.txt','w') as f:
f.write('pass')
with open('time.txt','r') as f:
content = f.readlines()
if content[0] != '_________________________________\n':
with open('time.txt','w') as f:
header= '_'*33+'\n'+\
'|Day |Month |Year |Hour |Minute |\n'
data = (f'|{t[0]} |{t[1]} |{t[2]}'
f'|{t[3]} |{t[4]} |\n')
f.write(header+seperator+data+end)
elif content[0] == '_________________________________\n':
with open('time.txt','r+') as f:
saved=f.readlines()[:-1]
f.seek(0)
data = (f'|{t[0]} |{t[1]} |{t[2]}'
f'|{t[3]} |{t[4]} |\n')
f.writelines(saved+[seperator2,data,end])
Output in the time.txt file(if it has been ran once):
_________________________________
|Day |Month |Year |Hour |Minute |
|---------------------------------|
|Tuesday |July |2022|03 |06 |
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|
Output(twice)(showing this to clarify that the data should be saved and re-printed):
_________________________________
|Day |Month |Year |Hour |Minute |
|---------------------------------|
|Tuesday |July |2022|03 |06 |
|=================================|
|Tuesday |July |2022|03 |06 |
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|
The output I want:
_________________________________
|Day |Month |Year |Hour |Minute |
|-------------------------------|
|Tuesday |July |2022|03 |06 |
|===============================|
|Tuesday |July |2022|03 |06 |
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|
The post I made at first is here: How to align strings in columns?
The one I didn't detail my post in maybe you could read the question I asked their and the answers.
Sorry for not adding detail the first time.
Any help would be appreciated, Thanks.