0

I am using python 2.7 .I am creating 3 lists (float values (if it matters at all)), i am using json object to save it in a file.

Say for eg.

L1=[1,2,3,4,5]
L2=[11,22,33,44,55]
L3=[22,33,44,55,66]
b={}
b[1]=L1
b[2]=L2
b[3]=L3
json.dump(b,open("file.txt","w"))

I need to read these values back from this "file.txt" into the 3 list. Can anyone please point me to the resource? How do i proceed with retrieving these values?

4

2 Answers 2

2

try

content = json.load(open('file.txt'))

or using a the with context manager to close the file for you:

with open('file.txt') as f:
    content = json.load(f)

Also, read the library's documentation

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, the Documentation really helped.
0

I used this following code:

import json
path=r"file.txt"
for line in open(path):
    obj = json.loads(line)

x=obj['1']
y=obj['2']
z=obj['3']

Now, i will have the List L1 in x, L2 in y and L3 in z

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.