samedi 15 juin 2019

Cannot solve Python ImportError: cannot import name 'FirstNews'

I'm currently making my own project with Python using Inheritance Class between if I select menu from Class A, Parents Class, then moves to Class B, Child Class, and also if I select menu from Class B, Child Class, I'd like to move to Class A. How to solve this problem?

I tried to make these files with Python Decorator, but Decorator can use one file. so I tried to use Python Inheritance to free movement between Class A and Class B, but to no avail.

this is the Main.py

    from FirstNews import FirstNews
    from Default import Default

    import datetime
    import random

    random.seed(datetime.datetime.now())

    class NaverNews:
        def __init__(self, news_lists):
        self.FirstNewsSite = news_lists
        self.Default = news_lists

        def __call__(self):
            print("Select the News site that you want to read")
            menu_input = input("Selection Menu")
            menu_list = []
            while 1:
                if menu_input is 1:
                    self.FirstNewsSite()
                    menu_list.append(FirstNews)

                else:
                    self.Default()
                    menu_list.append(Default)
                    break

This is the FirstNews.py

    import sys

    from Main import NaverNews
    from Default import Default

    sys.path.append('/NaverNews/Main/Main')


    # noinspection PyCallByClass
    class FirstNews(NaverNews):
    def __init__(self, my_choice):
        NaverNews.__init__(self, my_choice)
        self.myFirstChoice = my_choice
        self.mySecondChoce = my_choice
        self.myBackMenu = my_choice
        self.myDefault = my_choice

    def __call__(self):
        print("Select the News Company that you want to read")
        FirstInput = input()
        FirstList = []

        while 1:
            if FirstInput is 1:
                self.myFirstChoice()
                FirstList.append(NaverNews)
                # print("실행")

            elif FirstInput is 2:
                print("Going Back to Main.py")
                self.myBackMenu()
                FirstList.append(NaverNews)

            else:
                self.Default()
                FirstList.append(Default)
                break

This is the Default.py

     import sys

     from Main import NaverNews

     sys.path.append('/NaverNews/Main/Main')


     class Default(NaverNews):
         def __init__(self, myDefaultMenu):
             NaverNews.__init__(self, myDefaultMenu)
             self.myDefaultMenu = myDefaultMenu

         def __call__(self):
             print("You chose the wrong button\n Would you like to choose again? [Y / N]")
             DefaultInput = input()
             DefaultList = []

             if DefaultInput is 'y' or 'Y':
                 self.myDefaultMenu()
                 DefaultList.append(NaverNews)

             else:
                 print("Shut down the program")
                 exit(0)




Aucun commentaire:

Enregistrer un commentaire