Orpha Mortimer
Orpha Mortimer

Reputation: 13

Loading text file using json

I have already looked through multiple forums, and still can't find the answer to my question.

This is my code for writing to a file using json, which works:

def saveMember():
    import json
    with open("Members.txt", "w") as save:
        json.dump(memberList, save)

I can't figure out how to load this data back into my program. Can anyone help please?

Upvotes: 0

Views: 53

Answers (1)

Haha TTpro
Haha TTpro

Reputation: 5546

import json

with open('test.json', 'r') as f:
    obj = json.load(f)
    print (obj)

You should get the Python object which you put in json.dump

In your case, obj would be memberList

Upvotes: 1

Related Questions