使用导入的模块功能

时间:2015-02-11 17:49:46

标签: python function import module

我有一个名为menu的模块,我想从中调用其他各种模块。

def firststuff():

    import Add_data
    import Edit_data
    import View_Class
    import delete_data
    count1=0
    count2=0
    count3=0
    count4=0
    menu(count1,count2,count3,count4)


def menu(count1,count2,count3,count4):

    print("1.Add data")
    print("2.Edit data")
    print("3.View data")
    print("4.Delete Data")
    choice= input("Please select your choice")
    if choice == "1":
        Add_data.importantstuff()
    elif choice == "2":
        Edit_data()
    elif choice == "3":
        View_data()
    elif choice == "4":
        Delete_data()
    else:
        print("Sorry, this is not a valid input. Please try again")
        menu()        

firststuff()

我还没有完成其余选项的编码,它可能不是最优雅的代码,但我只想让它工作。当选择选项1时,它会出现:

AttributeError: 'function' object has no attribute 'importantstuff'

## This is my Add_data module

def importantstuff():

    import sqlite3
    Menu()

def Menu():

    print("1.Add classes")
    print("2.Add a new student")
    print("3. Add grades")                   
    print("4. Go back")
    menu= input("Please select a number")
    if menu =="1":
        Add_class()
    elif menu == "2":
        Add_new_student()
    elif menu =="3":
        ID =Add_grades()

        whereGrade(ID)

    elif menu =="4":
        import Menu
    else:
        print("That is an invalid input, please try again")

因此,您可以看到Add_data模块确实有一个函数importantstuff。我可能非常昏暗,但我无法弄清楚它为什么不运行这个功能?

0 个答案:

没有答案