import os.path
class Menu:
dic={}
def buildMenu(self):
file = "C:/Users/zz/Desktop/Class/menu.txt"
if os.path.isfile(file):
pass
else:
f=open("C:/Users/zz/Desktop/Class/menu.txt" ,"w")
name=input("Enter menu name")
while name!="":
price=input("Enter the price")
f.write(name+":"+price+"\n")
name=input("Enter menu name")
f.close()
f=open("C:/Users/zz/Desktop/Class/menu.txt" ,"r")
line=f.readline()
while line:
s=line.split(':')
print(s)
self.dic[s[0]]=s[1]
line=f.readline()
# s=line.split(':')
# self.dic[s[0]]=s[1]
f.close()
def showMenu(self):
for x,y in self.dic.items():
print(x+':'+y)
print(self.dic.items())
menu=Menu()
menu.buildMenu()
menu.showMenu()
I want line break after input codes.
SO I wrote f.write(name+":"+price+"\n")
My code works well.
If I print one line, \n
is not printing so it is fine.
But print the whole dictionary, \n
appears.
Also, \n
is not saved in menu.txt.
How can I remove \n
in the dictionary?