Python 官方文档:入门教程 => 点击学习
#Read and Write from Files##coding=utf-8import codecsf = open("AccountList.txt","w")L = u"张三\n李四\n王五\n赵六"f.write(L)f.clo
#Read and Write from Files#
#coding=utf-8
import codecs
f = open("AccountList.txt","w")
L = u"张三\n李四\n王五\n赵六"
f.write(L)
f.close()
f = open("AccountList.txt","r")
print (f.readline()) #read lines one by one
print (f.readline())
print (f.readline())
print (f.readline())
f.seek(0)
print (f.readlines()) #Output lines as a list
import linecache
m = open("AccountList01.txt","w")
n = u"America\nChina\nJapan\nEngland\nCanda\nGermany"
m.write(n)
m.close()
#m = open("AccountList01.txt","r")
#f.seek(0)
print(linecache.getline("AccountList01.txt",1));
print(linecache.getline("AccountList01.txt",2));
print(linecache.getline("AccountList01.txt",3));
print(linecache.getline("AccountList01.txt",1));
print(linecache.getline("AccountList01.txt",4));
print(linecache.getline("AccountList01.txt",5));
print(linecache.getline("AccountList01.txt",6));
--结束END--
本文标题: Python读取和写入文件
本文链接: https://lsjlt.com/news/184051.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0