Python读取和写入文件
2016-11-10 16:28
316 查看
#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));
#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));
相关文章推荐
- 使用Python读取和写入mp3文件的id3v1信息
- 【python coding 2:文件读写】读取本地文件里的ip地址,循环写入到新的文件中
- 关于python3.x读取写入文件时编码报错问题
- python中写入csv,excel显示、pandas读取csv文件的编码问题
- python 从shell读取指定文件以及写入指定文件
- 【原】Python 用例:二进制写入和读取文件内容
- Python读取某个目录下的zip压缩包解压开后计算每个小文件的md5值,并将压缩包名字、里面小文件名字、以及对应的md5值写入csv文件
- 如何用python读取和写入TIFF文件1
- ean13码的生成,python读取csv中数据并处理返回并写入到另一个csv文件中
- python从oracle读取数据写入到文件里
- python读取 .txt 文本内容以及将程序执行结果写入txt文件
- Python:读取文件并分词+文件写入
- python读取写入文件
- 如何用python读取和写入TIFF文件2
- Python将读取的SQL查询记录写入xls文件中
- Python 读取写入配置文件 —— ConfigParser
- python将对象写入文件,以及从文件中读取对象
- python 在excel文件中写入date日期数据,以及读取excel日期数据,如何在python中正确显示date日期。
- Python读取和写入Excel文件[整]
- Python学习笔记——文件写入和读取