Python方法完成自动合并文本文件操作,python文本文件,python方法合并多个
Python方法完成自动合并文本文件操作,python文本文件,python方法合并多个
python方法合并多个文本文件的自动操作,源代码参考:
# coding gbk #www.iplaypy.com import sys,os,msvcrt def join(in_filenames, out_filename): out_file = open(out_filename, 'w+') err_files = [] for file in in_filenames: try: in_file = open(file, 'r') out_file.write(in_file.read()) out_file.write('\n\n') in_file.close() except IOError: print 'error joining', file err_files.append(file) out_file.close() print 'joining completed. %d file(s) missed.' % len(err_files) print 'output file:', out_filename if len(err_files) > 0: print 'missed files:' print '--------------------------------' for file in err_files: print file print '--------------------------------' if __name__ == '__main__': print 'scanning...' in_filenames = [] file_count = 0 for file in os.listdir(sys.path[0]): if file.lower().endswith('[all].txt'): os.remove(file) elif file.lower().endswith('.txt'): in_filenames.append(file) file_count = file_count + 1 if len(in_filenames) > 0: print '--------------------------------' print '\n'.join(in_filenames) print '--------------------------------' print '%d part(s) in total.' % file_count book_name = raw_input('enter the book name: ') print 'joining...' join(in_filenames, book_name + '[ALL].TXT') else: print 'nothing found.' msvcrt.getch()
编橙之家文章,
相关内容
- Python math方法算24点代码详解,pythonmath,计算24点的方法
- 如何让Cookie.py模块用冒号做key,cookie.py冒号,python的Co
- Python制作 百度贴吧小爬虫.V0.1,python.v0.1,Python制作 百度
- 常见又实用的Python字符串操作小技巧,python字符串小技
- 按文件大小排序的python方法实现,文件大小排序python
- PycURL如何实现POST方法源码分享,pycurlpost,import pycur
- 阿拉伯数字转换成大写汉字的Python代码,阿拉伯python
- Python语言实现迅雷下载链接解析器源码,python下载链接
- python os模块获取文件夹大小的方法源代码,,用python o
- python语言求因数方法的实现源码,python因数,要想做到
评论关闭