I’m writing a program that looks through CSVs in a directory and appends the contents of each CSV to a list. Here’s a snippet of the offending code:
import glob
import re
c = glob.glob("*.csv")
print c
archive = []
for element in c:
look = open(element, "r").read()
open = re.split("\n+", look)
for n in open:
n = re.split(",", n)[0]
archive.append(n)
However, when I run this script, I get a TypeError: 'list' object is not callable. Can somebody please explain what’s going on?
I think it’s because you redefine
openas a list and call it in the next loop iteration.Just give the list another name.
Note that strings have a
split()method for when you don’t need a regex.