python一行一行讀取txt文件 python逐行讀取txt文件,每行為一個list?
python逐行讀取txt文件,每行為一個list?#Coding=UTF-8重新導(dǎo)入#您的文件路徑路徑=“/標(biāo)簽.txt“#read filefile=open(path,encoding=”UTF
python逐行讀取txt文件,每行為一個list?
#Coding=UTF-8
重新導(dǎo)入
#您的文件路徑
路徑=“/標(biāo)簽.txt“
#read file
file=open(path,encoding=”UTF-8“)
#定義一個規(guī)則
用于剪切字符串的序列=重新編譯(“s”)
結(jié)果=[?逐行讀取
對于文件中的行:
LST=順序拆分( 線條.strip())
item={
“name”:lst[0],
“val”:lst[1:
]}結(jié)果.append(項目)
(關(guān)閉文件文件.close()
打?。ńY(jié)果)
[
{
“name”:1,
“val”:[“v1”,“v2”
]},
{
“name”:2,
“val”:[“v1”,“v2”
]}
]