MVC architecture in pycharm user menu modifies and shows dataset

Viewed 47

Trying to get my menu to work with functionality first then reformat the structure into MVC. For some reason my menu is printing out however the prints in my if option==1 do not print and im not sure why they are not working as the menu is printing fine. I do know that I am missing some things however those print statements should work imo and im just confused as to where to go from here. Do i reformat the entire thing now and start over? Im brand new to python and using pandas was a first for me, any tips tricks or good info would be really appreciated as I am stuck and this is due shortly. Functionality of the menu is my main concern over the architecture.

The first portion of code simply reads and outputs the csv file (100 rows) using the pandas df.

Main class



import pandas as pd
import os

import View

'''variables to declare basic values such as name, filepath'''

csv_filepath = "C:/Users/Liam/PycharmProjects/assignment1/pipeline-incidents-comprehensive-data.csv"
Fname = "Liam Arscott"

'''Data frame reads the csv file using pandas, ensure utf-8 encoding'''

try:
    df = pd.read_csv(csv_filepath, encoding="utf-8")

except:
    '''written exception for if the file does not load'''
    print("file did not load or could not be located")

'''create list '''
C_list = []
for ind in df.index:
    '''index the df and append to the list'''
    col = (df['Incident Number'][ind], df['Incident Types'][ind], df['Reported Date'][ind],
           df['Nearest Populated Centre'][ind], df['Province'][ind], df['Company'][ind],
           df['Substance'][ind], df['Significant'][ind], df['What happened category'][ind])
    C_list.append(col)
    print(col)
    '''Create break statement once the for loop has gone over 100 times'''
    if ind == 99:
        break

class Menu:
    print("MENU")
    print("  1. Reload the data from the dataset")
    print("  2. Write dataset to new csv file")
    print("  3. Display 1 or many records")
    print("  4. Create a new record ")
    print("  5. Edit an existing record")
    print("  6. Delete an existing record")
    print("  7. Display all records")
    option = input("which menu option would you like?")

    if option == 1:
        print("refreshing data")
        print("data has been refreshed")

    if option == 2:
        with open("pipeline-incidents-comprehensive-data.csv", "r") as ffile, open("secfile.txt", "a") as secfile:
            for line in ffile:
                secfile.write(line)
        print(" dataset has been loaded to new file ")
0 Answers
Related