calendar = []
while True:
choice = input ("enter a,b,c,d or e")
if choice == "e":
print ("you have quitted this program")
break #to quit the entire program
if choice == "a":
newevent = input ("enter the name of an event you want to add")
y= int(input("enter the year of your event"))
m = int(input("enter the month of your event"))
d = int(input("enter the day of your event"))
h = int(input("enter the hour of your event"))
mi = int(input("enter the minute of your event"))
calendar.append ([newevent,y,m,d,h,mi])
print (calendar)
f = open("calendar.txt","w")
f.write (str(calendar)+"\n")
f.close()
f = open('calendar.txt','r')
st = f.readlines()
print (st)
for i in range (0,len(st)):
st[i] = st[i].strip("\n")
print (st)
f.close()
Это мой результат:
[['swim', 2020, 4, 2, 3, 2]]
["[['swim', 2020, 4, 2, 3, 2]]\n"]
["[['swim', 2020, 4, 2, 3, 2]]"]
Я хочу избавиться от квадратных скобок вокруг моего кода, чтобы он плавал, 2020,4,2,3,2. Обязательно ли открывать файл перед while True
?