-2

I tried this:

saves = open('filename','r')
Y = saves.readlines()
print(Y)

but I get the output [b'[0, 0, 0, 0, 0,]'] instead of [0, 0, 0, 0, 0,]

The text file content is [0, 0, 0, 0, 0]

(This not duplicate as the question is about something else and the answer didn't help me)

Qwertykey
  • 21
  • 5

1 Answers1

0

Use the Json module.

import json
Y = json.load(open('filename','r'))
print(Y)

Output

[0, 0, 0, 0, 0]

Demo:

>>> import json
>>> open('f.txt', 'w').write('[0, 0, 0, 0, 0]')
>>> y = json.load(open('f.txt', 'r'))
>>> y
[0, 0, 0, 0, 0]
cs95
  • 379,657
  • 97
  • 704
  • 746