赞
踩
摘要:主要介绍一些python的文件读取功能,文件内容修改,文件名后缀更改等操作。
批处理文件功能 import os
path1 = 'C:\\Users\\awake_ljw\\Documents\\python for data analysis\\test1'
path2 = 'C:\\Users\\awake_ljw\\Documents\\python for data analysis\\test2'
filelist = os.listdir(path1)
for files in filelist:
Olddir = os.path.join(path1,files)
filename = os.path.splitext(files)[0]
filetype = os.path.splitext(files)[1]
print Olddir
file_test = open(Olddir,'r')
Newdir = os.path.join(path2,str(filename)+'.csv')
print Newdir
file_test2 = open(Newdir,'w')
for lines in file_test.readlines():
strdata = ",".join(lines.split('\t'))
file_test2.write(strdata)
file_test.close()
file_test2.close()
os模块是python最基础的模块之一,一
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。