1

Here is my mydatatype.py

class answer(object):
    answer_start = 0
    text = ""
    def set(self,answer_start,text):
        self.answer_start = answer_start
        self.text = text



class quas(object):
    question = ""
    answers = answer()
    def set(self,question,answers):
        self.question = question
        self.answers = answers

class textandquas(object):
    context = ""
    qas = quas()
    def set(self,context,qas):
        self.context = context
        self.qas = quas()

class paragraph(object):
    content = []

Here is my console code:

import mydatatype as mdt
a = mdt.quas()

And the error happens. It happens with quas() and textandquas(), answer() and paragraph() are not affected. I believe this is some error related to python class-in-class. Are there any way that I can put a class in another class like that without nesting the class declaration ? Thank you in advanced.

8
  • 1
    Please post the full traceback in your question. If there's a mydatatype.pyc file (note the c at the end) delete it. Also, are you using iPython in some way (Spyder/Enthought Canopy for example)?
    – roganjosh
    Commented Nov 19, 2017 at 8:40
  • Also, your recent edit is pretty substantial. Is this new code representative of what's throwing the error?
    – roganjosh
    Commented Nov 19, 2017 at 8:44
  • Thank you for replying. The code edit is because the previous one is the wrong version. I'm using Spyder to run the code. Using answer() and paragraph() is okay. But using quas() gives error: a = mdt.quas() Traceback (most recent call last): File "<ipython-input-619-c5acadbd7098>", line 1, in <module> a = mdt.quas() AttributeError: 'module' object has no attribute 'quas'
    – Duke Le
    Commented Nov 19, 2017 at 9:22
  • Hold ctrl and press .. When it asks, click yes to restarting the kernal. Then try running your code.
    – roganjosh
    Commented Nov 19, 2017 at 9:28
  • I can't believe it! Turning it off and on actually works. Thanks a lot!
    – Duke Le
    Commented Nov 19, 2017 at 9:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.