I have read the other answers, but it seems I am still making a mistake somewhere.
I want to process all csv files in a given directory.
def main():
data = []
for root, dir, files in os.walk('/Users/me/Documents/ssbm csv/ssbm_stats/'):
for name in files:
# only csv files
if name.endswith(".csv"):
csvpath = os.path.join(root, name)
c = csv.reader(csvpath)
print "processing:", csvpath
games = makeT(c)
It runs but it does the wrong thing. It does not open the csv file using csv.reader()
.
def makeT(csvfile):
for row in csvfile:
print csvfile
print row
print len(row)
Output:
<_csv.reader object at 0x10d3ecde0>
['/']
1
The length is wrong. There is no slash character in any part of the csv file; so I think it may be doing something with the filename. I really do not understand why it isn't passing the file properly.
Any idea as how to pass file names to csv.reader()
?