首页 > 编程语言 > 详细

Python_04

时间:2017-11-07 23:41:15      阅读:284      评论:0      收藏:0      [点我收藏+]

1.Python  文件处理

打开文件---->读取内容---->获得内容

读取文件方式:  r  只读文件  w 只写模式 a 追加模式 

r+b 读写模式   w+b 写读模式  a+b 追加及读模式

def Write(firpath):
    f = open(firpath, r)
    for line in f.readlines():
        print(line)
  f.close() Write(
D:\\bird\day2\\test.txt)

追加模式

def Read(firpath):
    f = open(firpath, a)
    f.write(\njak, ok)
    f.flush()

Read(D:\\bird\day2\\test.txt)

 去掉读取文件的换行符

print(line, end=‘‘)

print(line.split())

print(line.strip())

print(line.strip(‘\n‘))

打印换行符

print(line.split(‘,‘))

文件阅读

readlines()读取出来是列表   readline()读出来是字符串

seek() 将指针移动你想要移动到的位置    tell()   定位指针的位置(以字符计算)

f.truncate() 从seek(0) 开始截图并保存在文件里

Python_04

原文:http://www.cnblogs.com/bamboocolor/p/7768900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!