コード例 #1
0
    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:
        print("Exiting Program")
コード例 #2
0
ファイル: Main.py プロジェクト: idrew4u/ITFnd100-Mod09
# Main Body of Script  ---------------------------------------------------- #
# TODO: Add Data Code to the Main body
lstEmployeeTable = []
lstFileData = []

# Load data from file into a list of employee objects when script starts
lstFileData = Fp.read_data_from_file("EmployeeData.txt")
for row in lstFileData:
        lstEmployeeTable.append(Emp(row[0], row[1], row[2].strip()))

# Show user a menu of options
while True:
    Eio.print_menu_item()

# Get user's menu option choice
    strChoice = Eio.input_menu_options()

    # Show user current data in the list of employee objects
    if strChoice == "1":
        Eio.print_current_list_items(lstEmployeeTable)
        continue

    # Let user add data to the list of employee objects
    elif strChoice == "2":
        lstEmployeeTable.append(Eio.input_employee_data())
        continue

    # let user save current data to file
    elif strChoice == "3":
        if("y" == str(input("Would you like to save data to file? (y/n): ")).strip().lower()):
            Fp.save_data_to_file("EmployeeData.txt", lstEmployeeTable)
コード例 #3
0
# Data #

strFileName = "EmployeeData.txt"
lstEmployeeTable = []  # A list/table of Employee objects
lstFileData = []  # A list/table of string objects in a list

# TODO: Add Data Code to the Main body (DONE)
#  Load data from file ionto a list of employee objects when sripts starts
lstFileData = Fp.read_data_from_file("EmployeeData.txt")
for row in lstFileData:
    lstEmployeeTable.append(Emp(row[0], row[1], row[2].strip()))

# Show user a menu of options
while True:
    Eio.print_menu_items()
    strOption = Eio.input_menu_options()  # Get users menu option choice
    if strOption == "1":
        # Show user current data in the list of employee objects
        Eio.print_current_list_items(lstEmployeeTable)
        continue
    elif strOption == "2":
        lstEmployeeTable.append(Eio.input_employee_data(
        ))  # Lets user add data to the list of employee objects
        continue
    elif strOption == "3":
        Fp.save_data_to_file(
            "EmployeeData.txt",
            lstEmployeeTable)  #Lets user save current data to file
        continue
    elif strOption == "4":  #Exit Program
        break
コード例 #4
0
# 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()
        for line in lstFileData:
コード例 #5
0
# list loop, creats emp object, populates it with employee properties from file
for list in lstEmpData:
    emp = Emp(list[0], list[1], list[2].strip())
    lstTable.append(emp)

# ------------------------------------------------------------------------ #

# Main Body of Script  ---------------------------------------------------- #

# Loop for main
while True:
    # Show user a menu of options
    Eio.print_menu_items()

    # Get user's menu option choice
    user_input = Eio.input_menu_options()

    # Show user current data in the list of employee objects
    if user_input == '1':
        Eio.print_current_list_items(lstTable)
    # Let user add data to the list of employee objects
    elif user_input== '2':
        emp = Eio.input_employee_data()
        lstTable.append(emp)
    # let user save current data to file
    elif user_input == '3':
        P.FileProcessor.save_data_to_file(file_name, lstTable)
    # Let user exit program
    elif user_input == '4':
        print('Have a nice day... or night. Exiting now...')
        exit()
コード例 #6
0
# 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
    elif strChoice == '2':  # checks if user entered 2
        try:  # check that code will run
            lstObjTable.append(Eio.input_employee_data()
                               )  # ask user to input new employee data
コード例 #7
0
    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

        else:
コード例 #8
0
else:
    raise Exception("This file was not created to be imported")
# Main Body of Script  ---------------------------------------------------- #

# Load data from file into a list of employee objects when script starts
fileName = 'EmployeeData.txt'
lstTable = []
lstFile = FP.read_data_from_file(fileName)
for line in lstFile:
    lstTable.append(E(line[0], line[1], line[2].strip()))

while True:
    # Show user a menu of options
    EIO.print_menu_items()
    # Get user's menu option choice
    userChoice = EIO.input_menu_options()
    # Show user current data in the list of employee objects
    if userChoice == '1':
        EIO.print_current_list_items(lstTable)
    # Let user add data to the list of employee objects
    elif userChoice == '2':
        lstTable.append(EIO.input_employee_data())
    # let user save current data to file
    elif userChoice == '3':
        FP.save_data_to_file(fileName, lstTable)
    # Let user exit program
    elif userChoice == '4':
        break
    else:
        raise Exception("Only enter values from 1-4.")
# Main Body of Script  ---------------------------------------------------- #
コード例 #9
0
# Data #
lstEmployeeTable = [] # A list/table of Employee objects
lstFileData = [] # A list/table of string objects in a list



# Load data from file into a list of employee objects when script starts 
lstFileData = Fp.read_data_from_file("EmployeeData.txt")
for row in lstFileData:
	lstEmployeeTable.append(Emp(row[0], row[1], row[2].strip()))

# Show user a menu of options
while True: 
	Eio.print_menu_items()
	# Get user's menu option choice
	strOption = Eio.input_menu_options() 
	if strOption == "1":
	# Show user current data in the list of employee objects
		Eio.print_current_list_items(lstEmployeeTable)
		continue
	elif strOption == "2":
	# Let user add data to the list of employee objects
		lstEmployeeTable.append(Eio.input_employee_data())
		continue
	elif strOption == "3":
		if("y" == str(input("Save this data to file? (y/n) - ")).strip().lower()):  # Double-check with user
			# Convert to function for processing
			Fp.save_data_to_file("EmployeeData.txt", lstEmployeeTable)
			input("Data saved to file! Press the [Enter] key to return to menu.")
		else:  # Let the user know the data was not saved
			input("New data was NOT Saved, but previous data still exists! Press the [Enter] key to return to menu.")
コード例 #10
0
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())
コード例 #11
0
class InvalidChoice(Exception):
    def __str__(self):
        return "Please choose from menu: option 1, 2, 3, or 4."


# initialize variables
strFileName = "EmployeeData.txt"

# Load data from file into a list of employee objects when script starts
lstEmployees = FileProcessor.read_data_from_file(strFileName)
EmployeeIO.print_current_list_items(lstEmployees)
# Show user a menu of options
while True:
    try:
        EmployeeIO.print_menu_items()
        intUserChoice = int(EmployeeIO.input_menu_options())
        if intUserChoice == 1:
            EmployeeIO.print_current_list_items(lstEmployees)
        elif intUserChoice == 2:
            newEmployee = EmployeeIO.input_employee_data()
            lstEmployees.append(newEmployee)
        elif intUserChoice == 3:
            FileProcessor.save_data_to_file(strFileName, lstEmployees)
        elif intUserChoice == 4:
            break
        else:
            raise InvalidChoice()
    except ValueError as e:
        print("Please choose number from options above!")
    except Exception as e:
        print("There was an error. The built in message from Python is:")
コード例 #12
0
# 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
        Fp.save_data_to_file(strFileName, lstOfEmployeeObjects)
コード例 #13
0
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
                print(objEmployee.first_name + " " + #Prints statement to user
                      objEmployee.last_name +
                      " has been added." + #Let's user know the name has been added
コード例 #14
0
    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
コード例 #15
0
# Main Body of Script  ---------------------------------------------------- #

# Load data from file into a list of employee objects when script starts
text_file = "EmployeeData.txt"
lstFileData = Fp.read_data_from_file(text_file)
lstTable = []
for line in lstFileData:
    lstTable.append(Emp(line[0], line[1], line[2].strip()))

while True:
    try:
        # Show user a menu of options
        Eio.print_menu_items()

        # Get user's menu option choice
        menu_choice = int(Eio.input_menu_options())

        # Show user current data in the list of employee objects
        if menu_choice == 1:
            Eio.print_current_list_items(lstTable)

        # Let user add data to the list of employee objects
        elif menu_choice == 2:
            new_emp = Eio.input_employee_data()
            lstTable.append(new_emp)

        # let user save current data to file
        elif menu_choice == 3:
            Fp.save_data_to_file(text_file, lstTable)

        # Let user exit program
コード例 #16
0
# 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())
コード例 #17
0
datafilename = "EmployeeData.txt"
EmployeeList = []

# 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
EmployeeList = DatabaseProcessor.stringlist_to_employeelist(
    FileProcessor.read_data_from_file(datafilename))

while True:
    # Show user a menu of options
    EmployeeIO.print_menu_items()
    # Get user's menu option choice
    userpicked = EmployeeIO.input_menu_options()

    if userpicked == "1":
        # Show user current data in the list of employee objects
        EmployeeIO.print_current_list_items(EmployeeList)
    elif userpicked == "2":
        # Let user add data to the list of employee objects
        EmpObj = EmployeeIO.input_employee_data()
        EmployeeList.append(EmpObj)
    elif userpicked == "3":
        # let user save current data to file
        DidIWork = FileProcessor.save_data_to_file(
            datafilename,
            DatabaseProcessor.employeelist_to_listforcsv(EmployeeList))

        if DidIWork: