美文网首页
Python快速入门(6):文件处理

Python快速入门(6):文件处理

作者: 大锅烩菜 | 来源:发表于2018-09-01 16:39 被阅读0次

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)  

相关文章

网友评论

      本文标题:Python快速入门(6):文件处理

      本文链接:https://www.haomeiwen.com/subject/nejuwftx.html