title: Python--String error
body: <p>Was given some code (I am using Python 3.2), and keep getting the below error. </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>But I am getting this error.</p>
  
  <blockquote>
    <p>Traceback (most recent call last): File "C:/Python32/test.py", line 21, in     writer.writerow([''] + actors) ValueError: I/O operation on closed file.</p>
  </blockquote>