标签:rip model 大文件 keyword 指定 spl loaded pwd 内容
# 读取文件,将文件的内容构造成指定格式的数据
文件:wlw|123|23
fsh|456|27
格式:a.["wlw|123|23","fsh|456|27"]
b.[["wlw","123","23"],["fsh","456","27"]]
c.[{“name":"wlw","pwd":"123","age":"23"},
{“name":"fsh","pwd":"456","age":"23"},
]
a.
v = []
with open(‘a.txt‘,mode=‘r‘,encoding=‘utf-8‘) as f:
for i in f.readlines():
v.append(i.strip())
print(v)
?
?
b.
v = []
with open(‘a.txt‘,mode=‘r‘,encoding=‘utf-8‘) as f:
for i in f.readlines():
v.append(i.strip().split(‘|‘))
print(v)
?
c.
v = []
with open(‘a.txt‘,mode=‘r‘,encoding=‘utf-8‘) as f:
for i in f.readlines():
dict = {}
a,b,c = i.strip().split(‘|‘)
dict[‘name‘] = a
dict[‘pwd‘] = b
dict[‘age‘] = c
v.append(dict)
print(v)
?
?
用readlines() 一行一行的读
with open(‘a.txt‘,mode=‘r‘,encoding=‘utf-8‘) as file:
for data in file.readlines():
print(data,end=" ")
?
标签:rip model 大文件 keyword 指定 spl loaded pwd 内容
原文地址:https://www.cnblogs.com/weiliwei-lucky/p/11155842.html