自己解决这个问题会非常令人欣慰,但我无法做到。
我想从包含字典形式数据的文本文件中获取随机值,例如:
{'One': '1111111', 'Two': '2222222', 'Three': '3333333'}
我尝试了一些变体,但代码目前是:
from random import *
table = open('file.txt')
random_value = random.choice(table.values())
当我尝试打印“random_value”(以查看它是否正常工作)时,出现错误:
AttributeError: 'file' object has no attribute 'values'