This is probably horribly sloppy, but here it is! This is a section from a large (imo) GUI program I am making. The below code is what triggers when a specific button is pressed.
def calc_platenumber(self): customer_firstname = str(self.customer2_entry.get()) customer_lastname = str(self.customer3_entry.get()) infile = open('license_numbers.txt', 'r') license_numbers = infile.readlines() infile.close() self.platenmb = random.choice(license_numbers) self.platenumber.set(self.platenmb) license_numbers.remove(self.platenmb) outfile = open('license_numbers.txt', 'w') for item in license_numbers: outfile.write(item) outfile.close() infile = open('used_license_numbers.txt', 'r') used_license_numbers = infile.readlines() infile.close() used_license_numbers.append(self.platenmb) used_license_numbers.append(customer_firstname) used_license_numbers.append(customer_lastname) outfile = open('used_license_numbers.txt', 'w') for item in used_license_numbers: outfile.write(item) outfile.close()
So, I have a GUI that asks for the first name and last name of the person. There is a generate button below that. The generate button will take a random license number from a large list of available numbers, remove it from that list, and then add it to a list of "used" license numbers. That is the function you see here. When it adds it to this second list, I want it to also take their name and add it as well. I have made it do that.
Problem is, whenever it adds it, it looks sloppy. No spaces or anything. I would rather it add on like...
Tim Bob C565213
And then whenever the next person uses the program, the file is updated to say...
Tim Bob C565213 Jim Bean 1234F324
...And so on. Currently it just looks sloppy, and even if sloppy won't matter (this is just a school project), it is going to bother me.