1.读文件
#1.打开
file = open("demo.txt","r")
#2.读取
s = file.read()
print(s)
# 3. 关闭
file.close()
2. 写文件
file = open("demo_w.txt","w")
file.write("hello")
file.write("\n")
file.write("world")
file.close()
3. 处理
file = open("worker.csv","r")
s = file.read()
info =[]
# split 将字符串分割为list
rows = s.split("\n");
for row in rows:
split_rows =row.split(",")
info.append(split_rows)
print(info)
网友评论