MCPcopy Create free account
hub / github.com/geekcomputers/Python / merge

Function merge

merge.py:14–35  ·  view source on GitHub ↗

merge csv files to one file

()

Source from the content-addressed store, hash-verified

12
13# the merge func
14def merge():
15 """merge csv files to one file"""
16
17 # indicates use of a global variable.
18 global resultfile
19
20 # use list save the csv files
21 csvfiles = [
22 f
23 for f in os.listdir(".")
24 if f != resultfile and (len(f.split(".")) >= 2) and f.split(".")[1] == "csv"
25 ]
26
27 # open file to write
28 with open(resultfile, "w") as writefile:
29 for csvfile in csvfiles:
30 with open(csvfile) as readfile:
31 print("File {} readed.".format(csvfile))
32
33 # do the read and write
34 writefile.write(readfile.read() + "\n")
35 print("\nFile {} wrote.".format(resultfile))
36
37
38# the main program

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected