Python中文
首页
教程
问答
标签
搜索
登录
注册
指使用inpu的字典
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>所以我有一个输入,它接受用户的输入,并使用它来尝试使用键定位正确的字典。它链接到一个.dat文件,该文件工作正常,可以定位字典。你知道吗</p> <p>如果我只是在运行程序之前输入位置就可以了:</p> <pre><code>print(useraccounts[56443]['forename']) </code></pre> <p>但是,当我使用输入来填写“56443”部分时,它将不起作用(表示“id\u find”的部分)</p> <pre><code> id_find = input('Enter the unique student ID: ') if os.path.exists('useraccounts.dat') == True: with open('useraccounts.dat', 'rb') as x: useraccounts = pickle.load(x) print(useraccounts[56443]['forename']) print('Student Found: ') print('\nForename: ', (useraccounts[id_find]['forename'])) print('Second name: ', (useraccounts[id_find]['surname'])) print('DOB: ', (useraccounts[id_find]['dob'])) print('Gender: ', (useraccounts[id_find]['gender'])) print('Username: ', (useraccounts[id_find]['username'])) print('Password: ', (useraccounts[id_find]['password'])) print('Class: ', (useraccounts[id_find]['class'])) </code></pre> <p>这是我得到的。您可以清楚地看到,它找到了我在运行程序之前输入键的字典(George是forename字段),但是当它使用输入来查找它时,它不起作用。你知道吗</p> <pre><code>Enter the unique student ID: 56443 George Student Found: Traceback (most recent call last): File "/Users/admin/Documents/Homework/Computing/spelling bee George Taylor.py", line 335, in <module> teacher_menu() File "/Users/admin/Documents/Homework/Computing/spelling bee George Taylor.py", line 224, in teacher_menu student_edit() File "/Users/admin/Documents/Homework/Computing/spelling bee George Taylor.py", line 28, in student_edit print('\nForename: ', (useraccounts[id_find]['forename'])) KeyError: '56443' </code></pre> <p>提前谢谢。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>字典由整数56443键入,您正在使用字符串“56443”进行搜索。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何重塑数组、迭代列的所有行并将重塑后的数组分配给新列?Python/Pandas/Numpy
1 回答
如何重塑数组的形状?
8 回答
如何重塑文本数据以适应keras的LSTM模型
9 回答
如何重塑未对齐的数据集,并使用numpy丢弃剩余数据?
2 回答
如何重塑此数据以使用绘图
7 回答
如何重塑此数据帧?
7 回答
如何重塑此数据集以适应RNN
2 回答
如何重塑没有列的数组?
1 回答
如何重塑测试数据帧,使其维数与训练和预测工作中使用的维数相同?
6 回答
如何重塑系列以在StandardScaler中使用它
2 回答
如何重塑线性回归的数据
7 回答
如何重塑线性回归的数据?
3 回答
如何重塑表格?
4 回答
如何重塑要堆叠的重复宽数据帧?
7 回答
如何重塑输入以放入二维层?
1 回答
如何重塑输入神经网络的三通道数据集
1 回答
如何重塑这个numpy数组
4 回答
如何重塑这个numpy数组以排除“额外维度”?
9 回答
如何重塑这个numpy阵列?
7 回答
如何重塑这个数据帧
10 回答