Getting callfunc from ast code.
Glich
Glich.Glich at googlemail.com
Sun Oct 28 14:09:28 EDT 2007
"""Hi, how can I extend the code shown below so that I can identify
any "CallFunc" in "func.code" and identify the value of "node" in
"CallFunc"? Thanks.
This is my code so far:
"""
""" Given a python file, this program prints out each function's name
in that file, the line number and the ast code of that function.
"""
import compiler
import compiler.ast
parse_file = compiler.parseFile("/home/glich/file.py")
count = 0
while count < (len(parse_file.node.nodes) - 1):
func = parse_file.node.nodes[count]
print "\nFunc name: " + str(func.name)
print "Func line number: " + str(func.lineno) + "\n"
print str(func.code) + "\n"
count += 1
"""file.py:
def fun1():
print "Hi"
hi = "1"
fun2()
fun4()
def fun2():
fun3()
def fun3():
fun4()
def fun4():
print "Hi"
fun1()
"""
More information about the Python-list
mailing list