I saw this SO question and tried using it by creating a .py file with 2 methods and trying to read it.
The file:
def f1(a):
print "hello", a
return 1
def f2(a,b):
print "hello",a,", hello",b
Trying to read it:
>>> r = open('ToParse.py','r')
>>> t = ast.parse(r.read)
Exception thrown:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python26\lib\ast.py", line 37, in parse
return compile(expr, filename, mode, PyCF_ONLY_AST)
TypeError: expected a readable buffer object
What am I doing wrong?
My goal is to get a python module and be able to parse it using Python - expose its classes and methods.
dir(),inspect,__dir__, etc. Looks like you are reinventing the wheel.r.readis a method. Surely you meantrorr.read()?