Today, my classmate gave me a txt file and asked him to read it with python.
I vowed to agree, but I didn't learn python much. But inadvertently found a clever way.
First of all, let’s take a look at the txt file that needs to be read:
I am also Xiaobai, so I searched the Internet for what to read CSV with panda, etc. It is not easy to use.
When I decided to handle the symbol [] by hand by myself.
Suddenly I think this file is so familiar! ! !
Is not that the python in the list of definitions it! !
So if you want to convert the string to read the code to perform thousand million! !
So just use a few lines of code to read it haha! Happy!
lines = open('20190319_15_36_40.txt','r')
for line in lines:
list1 = eval(line)#这里用eval将字符串转换为代码来执行
num=list1[0]
time=list1[1]
list2=list1[2]
print('序号:',num,'时间',time,'数据:',list2)
lines.close()
Hey, comrades engaged in network security are familiar with this eval haha~