从摘要到封装获取数据

时间:2019-05-23 17:39:19

标签: python abstract

我无法从设置为抽象的类中获取数据。在本节课中,如果我按“ 1”,它应该让我转到可以的地方

  • 输入名字和姓氏:
  • 输入地址:
  • 输入电话:
  • 输入电子邮件地址:

老实说,我不知道从哪里开始。

self.navigationItem.backBarButtonItem  = UIBarButtonItem(title: "Custom text here", style: .plain, target: nil, action: nil)

我跑步时遇到类似以下错误:

    class Student: # abstract
       def student_submenu (a,select_num):
         a.select_num = select_num

       def ss_1 (z):

         print("\n")
         print(" ===== | SUBMENU - STUDENTS | ===== ")
         print("||                                 ||")
         print("=====================================")
         print(" 1 - ADD NEW STUDENT")
         choice2 = input()
            while choice2 not in ['1', '2', '3', '4', '5']:
            print("Invalid Please try again")
            return select_num.student_submenu()



      def ss_2 (z1):
        if(choice2 == '1'):
        firstlast = input("Enter First name and last name: ")
        address = input("Enter Address: ")
        phone = input("Enter phone: ")
        email = input("Enter Email-Address: ") 
        print("\n")

        print(firstlast)
        print(address)
        print(phone)
        print(email)

  class Main:  #encapsulation
      def main_page(self):
        print("===== | MAIN MENU |=====")
        print("||                    ||")
        print("========================")
        print("1 - STUDENT ")
        print("2 - SUBJECT ")
        print("3 - QUIT ")
        allchoice = ['1', '2', '3'];
        choice = input()



       while choice not in allchoice:
         print("Invalid Please try again")
         choice = input()

       if choice == '1':
         a = Student()
         a.student_submenu

      elif choice == '2':
         print("back world")
      else:
        quit()

  mainout = Main()
  mainout.main_page()

2 个答案:

答案 0 :(得分:0)

我相信您的问题是由于缩进造成的。在Python中,缩进非常重要,必须保持一致。模块级别的任何内容都必须没有缩进,并且缩进时,您应该保持一致(通常默认为4个空格)

答案 1 :(得分:0)

要进一步回答该问题,请执行以下操作:您正在使用极其不一致和不正确的缩进。如果使用不正确的缩进,将导致很多错误,包括所得到的错误。

每个新块都应缩进4个空格(制表符也起作用),并且在全局范围内定义的所有内容(在这种情况下,是您的2个类和最后2行代码)都不应缩进。

尝试将您的代码更改为此:

class Student: # abstract
    def student_submenu (a,select_num):
        a.select_num = select_num

    def ss_1 (z):
        print("\n")
        print(" ===== | SUBMENU - STUDENTS | ===== ")
        print("||                                 ||")
        print("=====================================")
        print(" 1 - ADD NEW STUDENT")
        choice2 = input()
        while choice2 not in ['1', '2', '3', '4', '5']:
           print("Invalid Please try again")
        return select_num.student_submenu()



    def ss_2 (z1):
        if(choice2 == '1'):
            firstlast = input("Enter First name and last name: ")
            address = input("Enter Address: ")
            phone = input("Enter phone: ")
            email = input("Enter Email-Address: ") 

            print("\n")
            print(firstlast)
            print(address)
            print(phone)
            print(email)

class Main:  #encapsulation
    def main_page(self):
        print("===== | MAIN MENU |=====")
        print("||                    ||")
        print("========================")
        print("1 - STUDENT ")
        print("2 - SUBJECT ")
        print("3 - QUIT ")
        allchoice = ['1', '2', '3'];
        choice = input()



        while choice not in allchoice:
            print("Invalid Please try again")
            choice = input()
            if choice == '1':
                a = Student()
                a.student_submenu
            elif choice == '2':
                print("back world")
            else:
                quit()

mainout = Main()
mainout.main_page()

另请参阅: