首页 > 解决方案 > 如何编码字典值以输出超链接以打开本地文件

问题描述

我可以使用一些帮助。我有一个文本输入,它将输入与我的概念字典中的键进行比较,然后根据匹配的概念或概念,这会将相应的文件列为可点击的链接,以打开存储在文件字典中的文件。在这种情况下,文件将是 .py 并会打开 Sublime Text。(在代码中,文件被列为 .txt,但会将它们更改为 .py)

如何使文件字典中的文件成为可单击的链接,以打开与脚本位于同一目录中的本地文件?

谢谢你。

这是我第一次编码。我的目标是建立我的收藏,并有一种方法来回忆、重用、发展和掌握我的编码。

def print_big(word):
# use this to list python file and maybe a link to them to open
files    = {1:"http://file_title0001.txt",
            2:"http://file_title0002.txt",
            3:"http://file_title0003.txt",
            4:"http://file_title0004.txt",
            5:"http://file_title0005.txt",
            6:"http://file_title0006.txt",
            7:"http://file_title0007.txt",    
            8:"http://file_title0008.txt",
            9:"http://file_title0009.txt"}
# use this to change keys to simple keyword. 
concepts   = {'GAMES':[1,2,4,3,3],
              'BLACKJACK':[5,3,5,3,5],
              'MACHINE':[4,9,9,9,4],
              'DATABASE':[5,3,3,3,5],
              'LEARNING':[4,9,4,9,4]}
# choose more than one elements of concepts dictonary keys open more than one key value.
for pattern in concepts[word.upper()]:
    print(files[pattern])           
print_big(input("Enter Concept Idea: "))         

标签: pythonpython-3.x

解决方案


推荐阅读