from DataClasses import Employee as EmployeeClass from ProcessingClasses import FileProcessor as FPClass from IOClasses import EmployeeIO as IOClass else: raise Exception("This file was not created to be imported.") empList = [] # list of employees # On load, read data from text file and append each row to data list in context readfile = FPClass.read_data_from_file("EmployeeData.txt") for row in readfile: empList.append(EmployeeClass(row[0], row[1], row[2].strip())) # Operations while True: IOClass.print_menu_items() # display menu choice = IOClass.input_menu_options() # determine choice if choice == "1": IOClass.print_current_list_items(empList) # print data list in context continue elif choice == "2": dataAdded = IOClass.input_employee_data( ) # execute input_employee_data to determine data to be added empList.append(dataAdded) # add employee data to data list in context continue elif choice == "3": FPClass.save_data_to_file("EmployeeData.txt", empList) # save data list in context to file continue elif choice == "4": break # exit program
# RRoot,1.1.2030,Created started script # RShip 12.16.20 used template to complete scrip. # ---------------------------------------------------------- # if __name__ == "__main__": from DataClasses import Employee as Emp from ProcessingClasses import FileProcessor as Fp from IOClasses import EmployeeIO as Eio else: raise Exception("This file was not created to be imported") # Test data module objP1 = Emp(1, "Bob", "Smith") objP2 = Emp(2, "Sue", "Jones") lstTable = [objP1, objP2] for row in lstTable: print(row.to_string(), type(row)) # Test processing module Fp.save_data_to_file("EmployeeData.txt", lstTable) lstFileData = Fp.read_data_from_file("EmployeeData.txt") lstTable.clear() for line in lstFileData: lstTable.append(Emp(line[0], line[1], line[2].strip())) for row in lstTable: print(row.to_string(), type(row)) # Test IO classes Eio.print_menu_items() Eio.print_current_list_items(lstTable) print(Eio.input_employee_data()) print(Eio.input_menu_options())
print(row.to_string(), type(row)) # Test IO classes # TODO: create and test IO module Fp.save_data_to_file("EmployeeData.txt", lstTable) lstFileData = Fp.read_data_from_file("EmployeeData.txt") # Load data from file into a list of employee objects when script starts lstTable.clear() for line in lstFileData: lstTable.append(Emp(line[0], line[1], line[2].strip())) for row in lstTable: print(row.to_string(), type(row)) while (True): #Eio.print_current_list_items(lstTable) # Show current data in the list/table Eio.print_menu_items() # Show user a menu of options strChoice = Eio.input_menu_options() # Get user's menu option choice if strChoice == '1': # Add a new Task Eio.print_current_list_items(lstTable)# Show user current data in the list of employee objects continue # to show the menu elif strChoice == '2': #add new employee data print(Eio.input_employee_data()) # print new employee continue # to show the menu elif strChoice == '3': # # let user save current data to file #p.save_data_to_file("PersonData.txt", lstTable) Fp.save_data_to_file("EmployeeData.txt", lstTable) lstFileData = Fp.read_data_from_file("EmployeeData.txt") lstTable.clear()
else: raise Exception("This file was not intended for import") # data file_name = "EmployeeData.txt" empList = [] fileList = Fp.read_data_from_file(file_name) # pull data from file into list for row in fileList: empList.append(Emp(row[0], row[1], row[2].strip())) # main script using modules while True: # menu handling EmpIo.print_menu_items() usrCh = EmpIo.input_menu_options() # show current employees if usrCh == "1": EmpIo.print_current_list_items(empList) # user add employees elif usrCh == "2": empList.append(EmpIo.input_employee_data()) # save current data to file elif usrCh == "3": Fp.save_data_to_file("EmployeeData.txt", empList) print("Data was saved") else:
from DataClasses import Employee as EMP from ProcessingClasses import FileProcessor as FP from IOClasses import EmployeeIO as IO else: raise Exception('This file was not imported') # Main Body of Script ---------------------------------------------------- # # TODO: Add Data Code to the Main body # Load data from file into a list of employee objects when script starts lstFile = FP.read_data_from_file('EmployeeData.txt') lstTable = [] for line in lstFile: lstTable.append(EMP(line[0].strip(), line[1].strip(), line[2].strip())) # Show user a menu of options while (True): try: IO.print_menu_items() # Get user's menu option choice option = IO.input_menu_options() # Show user current data in the list of employee objects if option == '1': IO.print_current_list_items(lstTable) # Let user add data to the list of employee objects elif option == '2': lstTable.append(IO.input_employee_data()) # let user save current data to file elif option == '3': FP.save_data_to_file('EmployeeData.txt', lstTable) # Let user exit program elif option == '4': print('Thanks, goodbye') break
lstLstTable = [] # list of lists lstObjTable = [] # list of objects fn = "EmployeeData.txt" # file to read current employee data strChoice = "" # string to store user's choice # Main Body of Script ---------------------------------------------------- # # Load data from file into a list of employee objects when script starts lstTable = Fp.read_data_from_file(fn) # create a list of lists for i in lstTable: # iterate through the list of lists lstObjTable.append(Emp( i[0], i[1], i[2].strip())) # add employee object to list of objects while True: # Show user a menu of options Eio.print_menu_items( ) # use EmployeeIO class of IOClasses Module to print menu # Get user's menu option choice, and check for errors try: # check that code will run strChoice = Eio.input_menu_options() # store user's selection except Exception as e: # exception handled print(e) # print error message # Show user current data in the list of employee objects if strChoice == '1': # checks if user entered 1 Eio.print_current_list_items( lstObjTable) # print current list of employees input("Press [Enter] key to return to the menu. " ) # print message to continue # Let user add data to the list of employee objects
# Test Person class from DataClasses module objP1 = P("Nacho", "Libre") objP2 = P("Steven", "Esqueleto") objP3 = P("Sister", "Encarnación") lstTable = [objP1, objP2, objP3] for row in lstTable: print(row.to_string(), type(row)) # Check person objects # Test Employee class from DataClass module adding employee number (use existing data, not re-enter) objE1 = Emp(1, objP1.first_name, objP1.last_name) objE2 = Emp(2, objP2.first_name, objP2.last_name) objE3 = Emp(3, objP3.first_name, objP3.last_name) lstEmployees = [objE1, objE2, objE3] for row in lstEmployees: print(row.to_string(), type(row)) # Check employee objects # Test FileProcessor class from ProcessingClasses module FP.save_data_to_file("EmployeeData.txt", lstEmployees) # Save data lstFileData = FP.read_data_from_file("EmployeeData.txt") # Read data back in lstEmployees.clear() # Clear list for line in lstFileData: # Repopulate list lstEmployees.append(Emp(line[0], line[1], line[2].strip())) for row in lstEmployees: # Print list print(row.to_string(), type(row)) # Test IO classes Eio.print_menu_items() # check menu print Eio.print_current_list_items(lstEmployees) # print(Eio.input_employee_data()) print(Eio.input_menu_options())
from IOClasses import EmployeeIO # Test data module - class Person objP1 = Person("Bob", "Smith") objP2 = Person("Sue", "Jones") lstTable = [objP1, objP2] for row in lstTable: print(row.to_string(), type(row)) # Test data module - class Employee objP1 = Employee(1, "Bob", "Smith") objP2 = Employee(2, "Sue", "Jones") lstTable = [objP1, objP2] for row in lstTable: print(row.to_string(), type(row)) # Test processing module - class FileProcessor FileProcessor.save_data_to_file("EmployeeData.txt", lstTable) lstFileData = FileProcessor.read_data_from_file("EmployeeData.txt") lstTable.clear() for line in lstFileData: lstTable.append(Employee(line[0], line[1], line[2].strip())) for row in lstTable: print(row.to_string(), type(row)) # Test IO module - class EmployeeIO EmployeeIO.print_menu_items() EmployeeIO.print_current_list_items(lstTable) print(EmployeeIO.input_employee_data()) print(EmployeeIO.input_menu_options())
# Get user's menu option choice # Show user current data in the list of employee objects # Let user add data to the list of employee objects # let user save current data to file # Let user exit program # Main Body of Script ---------------------------------------------------- # # Read in current file and build a list of objects lstFileData = Fp.read_data_from_file(strFileName) lstOfEmployeeObjects.clear() for line in lstFileData: lstOfEmployeeObjects.append(Emp(line[0], line[1], line[2].strip())) while (True): eIO.print_menu_items() # show user the menu strChoice = eIO.input_menu_options() # Process user's menu choice if strChoice.strip() == '1': # Show Current list of products eIO.print_current_list_items(lstOfEmployeeObjects) continue # to show the menu elif strChoice == '2': # Add new employee data try: lstOfEmployeeObjects.append(eIO.input_employee_data()) except Exception as e: raise print(e) continue # to show the menu elif strChoice == '3': # Save Data to File
from IOClasses import EmployeeIO as Eio else: raise Exception("This file is not meant to ran by itself") # Main Body of Script ---------------------------------------------------- # # TODO: Add Data Code to the Main body # Load data from file into a list of employee objects when script starts lstTable = [] lstFileData = Fp.read_data_from_file("EmployeeData.txt") lstTable.clear() for line in lstFileData: lstTable.append(Emp(line[0], line[1], line[2].strip())) # Show user a menu of options while (True): Eio.print_menu_items() # Shows menu strChoice = Eio.input_menu_options() # Get user's menu option choice if strChoice.strip( ) == '1': # Show user current data in the list of employee objects for row in lstTable: line = row.to_string() print(row.to_string()) continue # to show the menu elif strChoice == '2': # Let user add data to the list of employee objects addEmp = Eio.input_employee_data() print(addEmp.first_name + " has been added") lstTable.append(addEmp) continue # to show the menu
# Declare variables strFileName = 'EmployeeData.txt' lstOfEmployeeRows = [] # Main Body of Script ---------------------------------------------------- # # Added code to main body to complete assignment 9 # Load data from file into a list of employee objects when script starts lstFileData = FP.read_data_from_file(strFileName) # load data from file for line in lstFileData: lstOfEmployeeRows.append(E(line[0], line[1], line[2].strip())) # add data to list # Show user a menu of options while True: eIO.print_menu_items() # Get user's menu option choice strChoice = eIO.input_menu_options() # Show user current data in the list of employee objects if strChoice.strip() == '1': eIO.print_current_list_items(lstOfEmployeeRows) # Let user add data to the list of employee objects elif strChoice.strip() == '2': objEmployee = eIO.input_employee_data() lstOfEmployeeRows.append(objEmployee) # add object to list # Let user save current data to file elif strChoice.strip() == '3':
for row in lstTable: print(row.to_string(), type(row)) # Test writing to PersonData.txt FP.save_data_to_file("EmployeeData.txt", lstTable) lstFileData = FP.read_data_from_file("EmployeeData.txt") lstTable.clear() for line in lstFileData: lstTable.append(EMP(line[0], line[1], line[2].strip())) for row in lstTable: print(row.to_string()) # Test IO class cont = True while cont == True: EIO.print_menu_items() strChoice = EIO.input_menu_options() if strChoice == "1": for row in lstTable: print(row.to_string()) elif strChoice == "2": EmpInput = [] EmpInput = EIO.input_employee_data() lstTable.append(EmpInput) for row in lstTable: print(row.to_string()) elif strChoice == "3": FP.save_data_to_file("EmployeeData.txt",lstTable) print("Data was saved to file") elif strChoice == "4": cont = False
# Show user a menu of options # Get user's menu option choice # Show user current data in the list of employee objects # Let user add data to the list of employee objects # let user save current data to file # Let user exit program # Main Body of Script ---------------------------------------------------- # if __name__ == "__main__": from DataClasses import Employee as Emp from ProcessingClasses import FileProcessor as Fp from IOClasses import EmployeeIO as Eio else: raise Exception("This file was not created to be imported") print(Eio.print_menu_items()) choice = Eio.input_menu_options() lstFileData = Fp.read_data_from_file("EmployeeData.txt") lstTable = [] lstTable.clear() for line in lstFileData: lstTable.append(Emp(line[0], line[1], line[2].strip())) while (True): if choice == "1": print(Eio.print_current_list_items(lstTable)) print(Eio.print_menu_items()) choice = Eio.input_menu_options() if choice == "2":
# Test data module lstOfEmployeeObjects = [] # A list of object rows strFileName = "EmployeeData.txt" # The target file for reading/writing strMenuChoice = "" # Captures user input for menu choice objFile = None # Object for opening/closing target file objEmployee = None # Object collecting user input data, 3 attributes # Main Body of Script ---------------------------------------------------- # # TODO: Add Data Code to the Main body (Done) # Load data from file into a list of employee objects when script starts lstOfEmployeeObjects = Fp.read_data_from_file(strFileName) print(lstOfEmployeeObjects) #Prints statement to user # Show user a menu of options while True: # While loop to let user choose their menu option Eio.print_menu_items() #Calls print_menu_items # Get user's menu option choice strChoice = Eio.input_menu_options() #Assigns the input of the menu option to strChoice # Show user current data in the list of employee objects if strChoice.strip() == "1": Eio.print_current_list_items(lstOfEmployeeObjects) #Prints list of employee objects continue # Takes us back to the main menu # Let user add data to the list of employee objects if strChoice.strip() == "2": while True: # While loop to let user add names try: objEmployee = Eio.input_employee_data() #Creates objEmployee lstOfEmployeeObjects.append(objEmployee) #Appends
else: raise Exception("This file was not created to be imported") # Global Variables -------------------------------------------------------------------- # strFileName = "EmployeeData.txt" lstTable = [] # A list that acts as a 'table' of rows strChoice = "" # Captures the user option selection # Main Body of Script ---------------------------------------------------- # # Load data from file into a list of employee objects when script starts try: # Use this Processor function to read a text file and return a table of data lstTable = Fp.read_data_from_file(strFileName) # read file data Eio.print_intro() # print the script intro here while True: Eio.print_menu_items() # print the menu here strChoice = Eio.input_menu_options() # Get menu option # Process user's menu choice if strChoice.strip() == '1': # Print the Employee Information Eio.print_current_list_items( lstTable) # <<Print the list of employees here Eio.input_press_to_continue() # send a message to the user elif strChoice == '2': # Enter New Employee ID's and names while True: # Use a While loop to allow for continued data entry # Use this Eio function to input a new Employee Id and Name Info strNewEmp = Eio.input_employee_data( lstTable) # Input New Employee Info here strEmpInfo = str( strNewEmp ) # Took the returned Employee info and set to this string variable here empID, empFirstName, empLastName = strEmpInfo.split(