代码拉取完成,页面将自动刷新
from __future__ import print_function
import os
# author:zhangshuyx@gmail.com
# !/usr/bin/env python
# -*- coding=utf-8 -*-
# define the result filename
resultfile = 'result.csv'
# the merge func
def merge():
"""merge csv files to one file"""
# indicates use of a global variable.
global resultfile
# use list save the csv files
csvfiles = [f for f in os.listdir('.') if f != resultfile \
and (len(f.split('.')) >= 2) and f.split('.')[1] == 'csv']
# open file to write
with open(resultfile, 'w') as writefile:
for csvfile in csvfiles:
with open(csvfile) as readfile:
print('File {} readed.'.format(csvfile))
# do the read and write
writefile.write(readfile.read() + '\n')
print('\nFile {} wrote.'.format(resultfile))
# the main program
def main():
print("\t\tMerge\n\n")
print("This program merges csv-files to one file\n")
merge()
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。