import csv from FormattedData import FormatData NewData = [ FormatData("George", 65, True), FormatData("Sally", 47, False), FormatData("Doug", 52, True) ] for Entry in NewData: print(Entry) def SaveData(Filename="", DataList=[]): with open(Filename, "w") as csvfile: DataWriter = csv.writer(csvfile, delimiter='\n', quotechar=" ", quoting=csv.QUOTE_NONNUMERIC) DataWriter.writerow(DataList) csvfile.close() print("Data saved!") SaveData("TestFile.csv", NewData)
from FormattedData import FormatData NewData = FormatData.ReadData("TestFile.csv") for Entry in NewData: print(Entry)
from FormattedData import FormatData NewData = [FormatData("Georges", 65, True), FormatData("Sophie", 47, False), FormatData("Pierre", 52, True)] for Entry in NewData: print(Entry)
from FormattedData import FormatData NewData = [ FormatData("George", 65, True), FormatData("Sally", 47, False), FormatData("Doug", 52, True) ] FormatData.SaveData("TestFile.csv", NewData)
from FormattedData import FormatData import os.path if not os.path.isfile("Testfile.csv"): print("Please run the CreateFile.py example!") quit() NewData = FormatData.ReadData("TestFile.csv") for Entry in NewData: print(Entry) print("\r\nAdding a record for Harry.") NewRecord = "'Harry', 23, False" NewData.append(NewRecord) for Entry in NewData: print(Entry) print("\r\nRemoving Doug's record.") Location = NewData.index("'Doug', 52, True") Record = NewData[Location] NewData.remove(Record) for Entry in NewData: print(Entry) print("\r\nModifying Sally's record.") Location = NewData.index("'Sally', 47, False") Record = NewData[Location] Split = Record.split(",") NewRecord = FormatData(Split[0].replace("'", ""), int(Split[1]), bool(Split[2])) NewRecord.Married = True
from FormattedData import FormatData NewData = [ FormatData("Georges", 65, True), FormatData("Sophie", 47, False), FormatData("Pierre", 52, True) ] FormatData.SaveData("TestFile.csv", NewData)
from FormattedData import FormatData NewData = [FormatData("Gerard", 65, True), FormatData("Sally", 47, False), FormatData("Daan", 52, True)] FormatData.SaveData("TestFile.csv", NewData)
from FormattedData import FormatData NewData = [ FormatData("Gerard", 65, True), FormatData("Sally", 47, False), FormatData("Daan", 52, True) ] for Entry in NewData: print(Entry)
import csv from FormattedData import FormatData NewData = [ FormatData("Ashish", 65, True), FormatData("Sally", 47, False), FormatData("Doug", 52, True) ] for Entry in NewData: print(Entry) def SaveData(Filename="", DataList=[]): with open(Filename, "w") as csvfile: DataWriter = csv.writer(csvfile, delimiter='\n', quotechar=" ", quoting=csv.QUOTE_NONNUMERIC) DataWriter.writerow(DataList) csvfile.close() print("Data saved!") SaveData("TestFile.csv", NewData)