我在尝试从两个列表中获取两个用户的输入时遇到问题。我将张贴代码,并试图解释
我有多个输入供用户选择选项。在这种情况下,它将选择: 1.)机架 2.)机架上的FDP 3.)FDP内的MOD
我对这些变量做了一些数学运算,得到一个“唯一标识符变量”,然后用它从列表中选择一个值。这就是我遇到的问题。我希望将列表中的值添加到下一个用户输入中,然后将它们组合起来查看另一个列表。示例:
#this is the list that looks at unique identifier variable. say I got 153, I would get water
selector = {
39:"test",
43:"r01c07f02-mb",
47:"r01c07f03-mc",
153:"water"
}
然后,我希望“water”添加[x],其中x是最后一个用户输入,然后查看其他列表:
water = {
1:{'Customer':'CID'},
2:{'Customer2':'CID2'},
3:"Third Option"
}
otherList = {
1:{'Customer3':'CID3'},
2:{'Customer4':'CID4'},
3:"TESTERS TESTEST"
}
因此,如果用户获得153作为唯一标识符,然后在最后一次输入时输入3,我希望打印“第三个选项”。但是,我只能让它打印“water[3]”或任何选项,但我无法让它实际打印water[3]中的值。这是我用来组合他们的代码,我知道这是错误的,但我不知道如何
def getInfo(arg1):
testVar = "blank" #just bs for testing
testVar = selector[arg1]
return testVar #returns whatever is in selector[arg1] spot, the unique identifier (uIdent) is passed as arg1 below
u = str(sInfo) #turning the last user input into a string because you cant add str to int (think this is where I am messing up)
conCat1 = "concat1 blank"
print("Here is first try: ")
print(conCat1) #will print 'concat1 blank'
conCat1 = getInfo(uIdent) + '[' + u + ']'
print("Here is second try: ") #will print whatever the value was next to unique ident in the selector list, + [sInfo], so water[3] or test[1] for examples
print(conCat1)
有人有什么想法可以帮我,或者给我指出正确的方向吗?请让我知道如果你需要额外的信息,或者如果我应该张贴整个代码(它只有约150行业余代码)。我不想把这篇文章搞得乱七八糟,我肯定它已经发布了完整的代码,但如果有人问我会的
编辑:基本上有没有一种方法可以将变量[x]的类型字符串转换为类型dict,这样它就可以打印变量[x]中的值,而不是实际的字符串变量[x]
目前没有回答
相关问题 更多 >
编程相关推荐