码迷,mamicode.com
首页 > 编程语言 > 详细

Python_04

时间:2017-11-07 23:49:19      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:split()   lin   打印   nes   style   for   文件的   strip()   end   

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

标签:split()   lin   打印   nes   style   for   文件的   strip()   end   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!