【发布时间】:2019-12-04 19:47:50
【问题描述】:
import random
import os
import json
class User:
def _init_(self, username, password, balance):
self.username = username
self.password = password
self.balance = balance
def file_read(source):
with open (source) as file:
data = file.read()
dictionary = json.loads(data)
return dictionary
然后外部文件就是这个
{"John":["pass123", 2000], "Jenson": ["pass123", 2000]}
我最初的想法是使用
for items in dict
但我不确定如何从最好由用户名命名的对象中创建多个对象
谢谢。
【问题讨论】:
-
上面显示的当前输入文件需要什么输出?
-
问题是什么?
-
当我使用``data = file_read(file directory)```
-
它将返回存储在外部文件中的字典并将其存储在该变量中
-
更新:感谢所有帮助的人,现在可以正常使用
标签: python dictionary oop