Here is my source code
class Shop:
def __init__(self, name="no name", color="no color", date="no date"):
self.__name = name
self.__color = color
self.__date = date
def setname(self, name):
self.name = name
return name
def setcolor(self, color):
self.color = color
return color
def setdate(self, date):
self.date = date
return date
def getInfo(self):
print("Name: ",self.__name)
print("Color: ",self.__color)
print("Date: ",self.__date + ("\n"))
ask_name, ask_color, ask_date = "", "", ""
counter, ask_user = 0, 0
while counter != 4:
ask_user = int(input("Would you like add information?\n1. Yes\t\t2. Open File\t\t3. Exit"))
while(True):
if ask_user == 1:
text_file = open("Text File.txt", "a")
ask_name = input("Instruction: You must save, before storing a new information.\nWhat is your name?")
ask_color = input("What is your favourite color?")
ask_date = input("What is your favourite date?")
text_file.write("\nName: %s\nColor: %s\nDate: %s\n\n" % (ask_name, ask_color, ask_date))
text_file.close()
print("You have a new Contact\nName:%s\nColor:%s\nDate:%s" % (ask_name, ask_color, ask_date))
break
if ask_user == 2:
text_file = open("Text File.txt", "r")
new_array = []
new_array = text_file.read()
print(new_array)
text_file.close()
break
if ask_user == 3:
print("\nYou saved your files successfully.")
raise SystemExit
An empty text file:
A text file with info in it:
Name: John Color: Yellow Date: Wednesday
Output
Name: Josh
Color: Yellow
Date: Wednesday
Name: John
Color: Green
Date: Tuesday
Name: James
Color: Red
Date: Monday
Expected Output
Name: Josh
Color: Yellow
Date: Wednesday
Name: John
Color: Green
Date: Tuesday
Name: James
Color: Red
Date: Monday
So my major problem I having at the moment is with space issues, I cannot figure out a way to remove the excessive amount of blank lines left. In addition, I would like to know if there is a way to remove information from the text file such as
Expected Output
Name: Josh
Color: Yellow
Date: Wednesday
# Removing John's information out of the list.
Name: James
Color: Red
Date: Monday
I heard that pop() function is good, but I am not sure about this situation though, when I want to remove multiple lines in specific location. So quick summary is I want to know if there is a way to remove multiple lines in specific location and how to remove the excessive lines in my text document.
Thanks in advancement, I would appreciate it.

New Topic/Question
Reply



MultiQuote




|