python - 尝试使用两个不同的用户输入从 Python 中的两个列表中获取信息
问题描述
我在尝试从两个列表中获取两个用户输入时遇到问题。我将发布代码并尝试解释。
我有多个输入供用户选择选项。在这种情况下,它选择: 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"
}
然后我希望“水”添加 [x],其中 x 是最后一个用户输入,然后查看其他列表:
water = {
1:{'Customer':'CID'},
2:{'Customer2':'CID2'},
3:"Third Option"
}
otherList = {
1:{'Customer3':'CID3'},
2:{'Customer4':'CID4'},
3:"TESTERS TESTEST"
}
因此,如果用户获得 153 作为唯一标识符,然后在最后一次输入时输入 3,我希望打印“第三选项”。但是,我只能让它打印“水 [3]”或任何选项,但我不能让它实际打印水 [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,以便它打印值 IN 变量 [x] 而不是实际的字符串变量 [x]
解决方案
推荐阅读
- c# - 使c#线程中的代码段不可中断
- reactjs - ReactJS 表单提交 this.props.history.push('/downloads') 未链接到新页面
- tableau-api - Tableau 获取过去 30 天的非活动用户
- integromat - 如何在我的自定义 Integromat 应用程序中上传文件?
- java - 如何在 Eclipse 中将多个 java 文件导出为单个可运行的 jar 文件?
- python - 如果字符串名称完全相同,则获取变量的值
- email - 发送网格电子邮件可能在黑名单上
- android - Android Studio 不会创建新的活动或片段
- ios - TabBar 在使用 Segue 返回到 TabBarController 的初始 ViewController 后被隐藏
- c# - PC离线时有时无法连接到SQLLocalDB