title: How to parse a Python module from file
body: <p>I saw <a href="https://stackoverflow.com/questions/4650110/parse-python-file-and-evaluate-selected-functions">this SO question</a> and tried using it by creating a <code>.py</code> file with 2 methods and trying to read it.<br>
  The file:  </p>
  
  <pre><code>def f1(a):
      print "hello", a
      return 1
  
  def f2(a,b):
      print "hello",a,", hello",b
  </code></pre>
  
  <p>Trying to read it:  </p>
  
  <pre><code>&gt;&gt;&gt; r = open('ToParse.py','r')
  &gt;&gt;&gt; t = ast.parse(r.read)
  </code></pre>
  
  <p>Exception thrown:  </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;interactive input&gt;", line 1, in &lt;module&gt;
    File "C:\Python26\lib\ast.py", line 37, in parse
      return compile(expr, filename, mode, PyCF_ONLY_AST)
  TypeError: expected a readable buffer object
  </code></pre>
  
  <p>What am I doing wrong?<br>
  <strong>My goal</strong> is to get a <code>python</code> module and be able to parse it using <code>Python</code> - expose its classes and methods.</p>