python - 如何编码字典值以输出超链接以打开本地文件
问题描述
我可以使用一些帮助。我有一个文本输入,它将输入与我的概念字典中的键进行比较,然后根据匹配的概念或概念,这会将相应的文件列为可点击的链接,以打开存储在文件字典中的文件。在这种情况下,文件将是 .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: "))
解决方案
推荐阅读
- mysql - 检索按日期过滤的每个组中的最后一条记录 - MySQL
- python - Pandas 在日期系列的 24 小时内查找行
- django - 自动创建相关模型
- datetime - 在 sqlite 中创建具有默认当前时间的日期时间列
- java - 为什么我不能在公共起落架方法中调用私有绘制方法?
- swift - 将目标添加到 Swift 中的按钮
- python - python中的正则表达式不匹配
- android - 当按钮处于不同布局时如何使用 onClickListener?
- java - Secured JMS queue connection jboss
- bash - 使用 Bash 脚本获取带有 ${parameter##word} 的子字符串