Was given some code (I am using Python 3.2), and keep getting the below error.
import csv
import collections
import itertools
grid = collections.Counter()
with open("test1.csv", "r") as fp:
reader = csv.reader(fp)
for line in reader:
for pair in itertools.combinations(line, 2):
grid[pair] += 1
grid[pair[::-1]] += 1
actors = sorted(set(pair[0] for pair in grid))
with open("connection_grid.csv", "wb") as csvfile:
writer = csv.writer(fp)
writer.writerow([''] + actors)
for actor in actors:
line = [actor,] + [grid[actor, other] for other in actors]
writer.writerow(line)
But I am getting this error.
Traceback (most recent call last): File “C:/Python32/test.py”, line 21, in writer.writerow([”] + actors) ValueError: I/O operation on closed file.
If
bis in the mode then the file is opened in binary mode, not text mode. Remove it.