python 文件处理方法简介

利用python处理文件

一、File(文件) 方法
打开文件:open(file, mode=’r’)
关闭文件:file.close()
读取文件:file.read([size])、file.readline([size])、file.readlines([sizeint])
移动文件读取指针到指定位置:file.seek(offset[, whence])
写入文件:file.write(str)、file.writelines(sequence)

二、EXCEL文件
python对于excel文件有处理模块:读取用xlrd、写入用xlwt
安装命令:pip install xlrd
引用代码:import xlrd
官网:http://www.python-excel.org/

三、配置文件
比如配置文件config.ini或config.txt
安装命令:pip install configparser
引用代码:import configparser
pypi:https://pypi.org/project/configparser/