title: How do I open a file, passed to open as a variable?
body: <pre><code>def readfile(file):
      edges = [] # to contain tuples of all edges
  
      with open(file) as f: 
          for line in f:
  </code></pre>
  
  <p>I'm trying to pass in a text file called file, then read it, but it doesn't work.  Even if I cast file to a string it doesn't work.
  Python says</p>
  
  <pre><code>with open(file) as f: IOError: [Errno 22] invalid mode ('r') or
  filename: "&lt;type 'file'&gt;"
  </code></pre>
  
  <p>How do I open a file, passed to open as a variable?</p>