For a part of my program it is necessary that the user enters the date and to view this date, each product Is checked against if the product is due to end the product before or after the date the user entered the shelf life from the date and its shelf life. Import import import import datetime cheeseDictionary = {} userInput = "" def loadProduct (fileName): global cheeseDictionary f = open (fileName, "r") line = f The line: line = line [: - 1] data = partition (line, data: [2], "name": data [3]} # stores [data]: .readline () # reads the line from the file: "Data": data [1], "life": data [3]} # data each divided item line = f.readline () # next line f.close () def saveProduct (fileName, cheeseDictionary): sorted ( For cheeseDictionary.keys ()) I for f = open (fileName, "w"): v = CheeseDictionary [I] f.write ("% s:% s:% s:% s \ n"% (i, v ["date"], v ["life"], v ["name"])) f. "Add" ("name"), "life" ("day"), "", "name", print cheese, cheese, cheesecake [cheese] ["(" name ") for cheese in close prune paste. Global PracticeIonline = 0 idInput = "dateInput =" "lifeInput =" "," "Nameinput =" "while true! = 1: idInput = raw_input (Enter the cheese id to add. ") If the percussion. Has_key (idInput): print (" This ID already exists, please try again. ") Correct = 0 and: new id = id input correct = 1 date input = raw_input (" please date of cheese Enter format dd / mm / yyyy. ") LifeInput = raw_input (" Please enter the life of the cheese to be added in days. ") NameInput = raw_input (" Please add the name of cheese to add. ") CheeseDictionary [IdInput] = {"date": dateInput, "life": lifeInput, "name": nameInput} def check product (cheeseDictionary): dateCheck = raw_input ("please" Or date in the date dd / mm / yyyy: ") Cheese in cheesecaster:
I know that the dates need to be stored in the date format of the date, but I believe how to do this. If I understand correctly, then you need to change the strings representing the stars in the format "dd / mm / yyyy". In date time objects?
If yes, then we need E law For example: datetime import datetime from D = datetime.strptime ("28/03/2011", "% d /% m /% Y") print repr (d)
> < / Pre> This prints:
datetime.datetime (2011, 3, 28, 0, 0)
Comments
Post a Comment