python一行一行读取txt文件 python逐行读取txt文件,每行为一个list?

python逐行读取txt文件,每行为一个list?#Coding=UTF-8重新导入#您的文件路径路径=“/标签.txt“#read filefile=open(path,encoding=”UTF

python逐行读取txt文件,每行为一个list?

#Coding=UTF-8

重新导入

#您的文件路径

路径=“/标签.txt“

#read file

file=open(path,encoding=”UTF-8“)

#定义一个规则

用于剪切字符串的序列=重新编译(“s”)

结果=[?逐行读取

对于文件中的行:

LST=顺序拆分( 线条.strip())

item={

“name”:lst[0],

“val”:lst[1:

]}结果.append(项目)

(关闭文件文件.close()

打印(结果)

[

{

“name”:1,

“val”:[“v1”,“v2”

]},

{

“name”:2,

“val”:[“v1”,“v2”

]}

]