I am self learning python and I encountered a problem when my code tries reading a list saved in txt:
I have a series of number sets saved in the txt: for example the data in txt is as follow:
[5,26,39]
[7,21,40] …
I have tried the following 2 codes to read the above txt:
data = open(r"201219.txt", 'r')
lines = data.readlines()
for line in lines:
for i in line:
print(i)
AND
with open(r"201219.txt", 'r') as data:
lines = data.read().splitlines()
for line in lines:
for i in line:
print(i)
Both of the above codes will print something like: enter image description here
It seems the code is reading each character instead of a number itself. I can't iterate through the items as it is not what I want.
Does anyone know how to deal with this? Thanks very very much.