字典按键调用

发布于 2024-11-04 03:29:46 字数 658 浏览 2 评论 0原文

我正在构建一个测试程序。它本质上是一个错误和错误修复的数据库。它可能最终成为我在 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)        

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

谢谢, 前舒。

im building a test program. its essentially a database of bugs and bug fixes. it may end up being an entire database for all my time working in python.
i want to create an effect of layers by using a dictionary.

here is the code as of april 29 2011:

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)        

now when i use this i get the ENTIRE dictionary, not just the first layer. how would i do something like this? do i need to just list links in the console? or is there a better way to do so?

thanks,
Pre.Shu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤檠 2024-11-11 03:29:47

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

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 ..."

I'm not quite sure what you want, but to print the content of a single key of dictionary you index it:

syntax['PRINT']

Maybe this help a bit:

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 ..."
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文