When ever I try to load data from a json file I get this error:
AttributeError: ‘list’ object has no attribute ‘load’
What I expected
import json
users=[]
with open('username project.json','w') as f:
jfile=json.dump(users,f)
def create_usernames():
username=input('Enter in username')
with open('username project.json','r+') as read:
usersj=users.load(read)
if username in users[usersj]:
print('username rejected')
else:
print('username is okay')
create_usernames()
What resulted
usersj=users.load(read)
AttributeError: 'list' object has no attribute 'load'
2
Answers
are you trying to load the json users? because list doesn’t have any load method
There’re couple of typos in your code, and I corrected accordingly
Tested both the scenarios where a username exists and does not exist