0

I wanted to make a Simple gui with wxpython (In python 3.6.1) because i didn't want to use the commandline for this project anymore.

I have a big file for the Logic in another file, that is also used by other non wxpython files.

But when I try to import my Logic class I Get this error :

ImportError: cannot import name 'QuestionAsk'

I use this Line to import the Logic class :

from Get import QuestionAsk

The file "Get.py" is in the same directory as the gui file. Here

But it dosen't work why and how can I import this file ?

By the way I call the gui.py file from the get.py file and import the get.py file from the Asker.py file.

ps : Pleas try to not answer :" just copy the content of that class into your gui file" because i use this class elsewhere if there is no other solution then that's ok but that's just ugly and unefficient.

Edit Here is code from the Get file that starts the Gui :

def graphical_start():
    app = wx.App(False)  # int app
    frame = GuiVocCard()  # set frame (GuiVocCard is in the main Gui File)
    frame.Show()  # show frame
    app.MainLoop()  # execute loop

And here is The Start of the main Gui class "GuiVocCard" :

class GuiVocCard(wx.Frame):

    def __init__(self):

        self.language = "es"
        self.transList = "C:\\Users\\Justus\\Desktop\\Schule\\spa\VocabGeter\\translations\\big_translation.json"
        self.verb_forms = [0,2]
        self.High_Score = 0
        self.s_file = "scores.json"
        self.S_chunk = 40
        self.chunk_file = "chunks.json"

       self.load_config()
       self.q_ask = QuestionAsk(lan=self.language, trans=self.transList, verb_forms=self.verb_forms,
                             scores_file=self.s_file, chunks_file=self.chunk_file, chunk_size=self.S_chunk)
       ...

Edit 2 :

The QuestionAsk is defined here in the Get.py file:

class QuestionAsk:

   def __init__(self,lan="es",trans="C:\\Users\\Justus\\Desktop\\Schule\\spa\VocabGeter\\translations\\translation.json"
             ,verb_forms=[0,2],scores_file="scores.json",chunks_file="chunks.json",chunk_size=40):

       self.language = lan
       self.transList = trans
       self.verb_forms = verb_forms
       self.High_Score = 0
       self.s_file = scores_file
       self.S_chunk = chunk_size
       self.chunk_file = chunks_file

Fixed it (yay) :

I removed the graphical_start function from the Get.py file and pasted it into the gui.py file . I now import the Gui.py file directly from the Asker.py file .

Sutsuj
  • 73
  • 1
  • 10
  • try `from Get.py import QuestionAsk` – Max May 31 '18 at 14:52
  • ModuleNotFoundError: No module named 'Get.py'; 'Get' is not a package – Sutsuj May 31 '18 at 14:54
  • try `from .Get import QuestionAsk` – vk-code May 31 '18 at 14:54
  • Fairs, would be helpful to see a code Snippet of Get.py? – Max May 31 '18 at 14:55
  • from .Get import QuestionAsk gives my this error : ImportError: attempted relative import with no known parent package – Sutsuj May 31 '18 at 14:56
  • Wich part it is 27kb ? – Sutsuj May 31 '18 at 14:57
  • @JustusLaube the part where QuestionAsk is defined, doesn't have to include all of QuestionAsk, and also maybe the initial definition of Get, just to properly know – Max May 31 '18 at 14:59
  • @JustusLaube you forgot to include where the class QuestionAsk is defined,(this `class QuestionAsk()`). Is QuestionAsk a sub class of something in Get.py? If it is a subclass, import it through `from Get import ParentClass.QuestionAsk` – Max May 31 '18 at 15:07
  • the Clask Question Ask has no parent class . – Sutsuj May 31 '18 at 15:13
  • Have a look here: (Possible duplicate) https://stackoverflow.com/questions/9252543/importerror-cannot-import-name-x – Max May 31 '18 at 15:16
  • Thanks Max , I fixed it ! I just moved the "graphical_start" function from the Get.py file into the gui.py file and import the gui.py file directly from the Asker.py file. – Sutsuj May 31 '18 at 15:24

0 Answers0