Class 从同一目录导入类时出现问题

Class 从同一目录导入类时出现问题,class,import,Class,Import,很抱歉,如果这看起来是一个非常琐碎的问题,但我已经尝试了一段时间从同一目录中的单独文件导入一个类。我一直在使用“from file_name import Class”代码,当所有代码都在同一个文件中时,代码才起作用,只有当它被拆分时,我才会收到错误消息“问题未定义”。以下是包含类(称为survey)的文件中的代码: 下面是使用该类的代码: from survey import AnonymousSurvey question = "What language can you spe

很抱歉,如果这看起来是一个非常琐碎的问题,但我已经尝试了一段时间从同一目录中的单独文件导入一个类。我一直在使用“from file_name import Class”代码,当所有代码都在同一个文件中时,代码才起作用,只有当它被拆分时,我才会收到错误消息“问题未定义”。以下是包含类(称为survey)的文件中的代码:

下面是使用该类的代码:

from survey import AnonymousSurvey

question = "What language can you speak?"

my_survey = AnonymousSurvey(question)

my_survey.show_question()

print("If you would like to quit press q")
while True:
    response=input("languages")
    if response == "q":
       break
    my_survey.collect_response(response)
   
    
my_survey.show_results()
很抱歉,如果这看起来很琐碎,我对编码非常陌生,我非常感谢您的帮助,因为我已经花了很长一段时间在这方面:)

我收到错误消息“问题未定义”


实际上,
问题
未在此函数中定义;你的意思当然是自我提问

谢谢你的评论。我试过了,它出现了一条错误消息:“没有名为'survey.py'的模块;'survey'不是一个包”哦,文件名已经是survey.py,它保存为python文件抱歉,我没有在问题中指定它!我试过了,但它仍然说名字问题没有定义。下面是完整的错误消息:“回溯(最近一次调用):文件“C:/Users/Ahmed/OneDrive/Documents/Python Scripts/Practicing files/Testing code/language_survey.py”,第7行,在my_survey.show_question()文件“C:/Users/Ahmed/OneDrive/Documents/Python Scripts/Practicing files/Testing code\survey.py”“,第6行,在show_question print(question)name错误:名称'question'未定义“感谢您的帮助:)抱歉,我没有对错误消息给予足够的注意;我更正了答案。感谢您现在提供的有意义的帮助!
from survey import AnonymousSurvey

question = "What language can you speak?"

my_survey = AnonymousSurvey(question)

my_survey.show_question()

print("If you would like to quit press q")
while True:
    response=input("languages")
    if response == "q":
       break
    my_survey.collect_response(response)
   
    
my_survey.show_results()
    def show_question(self):
        print(question)