【问题标题】:dictionary key-call字典键调用
【发布时间】:2011-08-16 02:41:03
【问题描述】:

我正在构建一个测试程序。它本质上是一个错误和错误修复的数据库。它可能最终成为我在 python 中工作的所有时间的整个数据库。 我想通过使用字典来创建图层效果。

这是截至 2011 年 4 月 29 日的代码:

modules=['pass']
syntax={'PRINT':''' in eclipse anthing which 
you "PRINT" needs to be within a set of paranthesis''','StrRet':'anytime you need to use the return action in a string, you must use the triple quotes.'}

findinp= input('''where would you like to go?
Dir:''')
if findinp=='syntax':
    print(syntax)
    dir2= input('choose a listing')
    if dir2=='print'or'PRINT'or'Print':
        print('PRINT' in syntax)        

现在当我使用它时,我得到了整个字典,而不仅仅是第一层。我该怎么做这样的事情?我需要在控制台中列出链接吗?还是有更好的方法?

谢谢, 舒前。

【问题讨论】:

  • 正确格式化你的源代码!

标签: python eclipse dictionary pydev


【解决方案1】:

我不太确定你想要什么,但要打印字典的单个键的内容,你可以索引它:

syntax['PRINT']

也许这有点帮助:

modules=['pass']
syntax={
    'PRINT':''' in eclipse anthing which 
you "PRINT" needs to be within a set of paranthesis''',
    'STRRET':'anytime you need to use the return action in a string, you must use the triple quotes.'}

choice = input('''where would you like to go?
Dir:''').upper()

if choice in syntax:
    print syntax[choice]
else:
    print "no data ..."

【讨论】:

  • 在输出中我得到了:你想去哪里? Dir:syntax {'PRINT': ' in eclipse anthing which \nyou "PRINT" 需要在一组括号内', 'StrRet': '任何时候你需要在一个字符串中使用返回动作,你必须使用三引号。'} 选择我想获得的列表:你想去哪里? Dir:syntax 语法包含: PRINT 和 StrRet Dir:Print ' in eclipse anthing \nyou "PRINT" 需要在一组括号内' 还有什么?是或否:是 程序关闭
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-06-11
  • 2016-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多