我试图自学Python,并创建了一个文件,该文件贯穿了分布在各个班级的各种问题集。在这个文件的结尾,我想总结一下我所有的原始输入。你知道吗
不幸的是,我很难从一个单独的类访问这些值。我已经将我的代码分解为一个测试示例来演示我的程序结构:
class QuestionSet(object):
next_set = 'first_set'
class ClaimEngine(QuestionSet):
def current_set(self):
last_set = "blank"
while_count = int(0)
quizset = Sets.subsets
ParentSet = QuestionSet()
while ParentSet.next_set != last_set and int(while_count)<50:
quizset[ParentSet.next_set].questioning()
while_count = while_count+1
class FirstSet(QuestionSet):
def questioning(self):
value1 = raw_input("Val1")
QuestionSet.next_set = "second_set"
class SecondSet(QuestionSet):
def questioning(self):
value2 = raw_input("Val2")
QuestionSet.next_set = "summary"
class Summary(QuestionSet):
print "test"
## I need to print a summary of my inputs here ##
## e.g. Print "The answer to value1 was:%r" %value1##
class Sets(object):
subsets = {
'first_set': FirstSet(),
'second_set': SecondSet(),
'summary': Summary()
}
我尝试在摘要中定义每个类,例如1stSet=FirstSet(),然后第一组值1等等,但没有用。你知道吗
如果有人对如何找回这些价值观有什么建议的话,那就太好了,因为我已经写了一个充满问题的大型程序,在最后的关卡上摔倒了!你知道吗
谢谢你。你知道吗
您在类的每个函数中拥有的值不会创建为类成员。对于您的应用程序,您需要创建成员变量来存储类中的值。你知道吗
例如:
现在value1是一个成员变量,您可以访问它。你知道吗
在上面的示例中,它可能类似于下面的行,从“first\u set”访问value1
如果你不熟悉这个,试试看 this tutorial
相关问题 更多 >
编程相关推荐