pycharm用户菜单中的MVC架构修改并显示数据集

发布于 2025-01-10 00:16:09 字数 2130 浏览 0 评论 0原文

首先尝试让我的菜单与功能一起使用,然后将结构重新格式化为 MVC。由于某种原因,我的菜单正在打印,但是我的 if option==1 中的打印不打印,我不确定为什么它们不起作用,因为菜单打印正常。我确实知道我错过了一些东西,但是在我看来,这些打印语句应该有效,我只是对从这里去哪里感到困惑。我现在要重新格式化整个内容并重新开始吗?我对 python 是全新的,使用 pandas 对我来说是第一次,任何提示技巧或好的信息都将非常感激,因为我被困住了,这很快就会到期。菜单的功能是我对架构的主要关注点。

代码的第一部分只是使用 pandas df 读取并输出 csv 文件(100 行)。

主班



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 ")

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 ")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文