参考:
symtable — Access to the compiler’s symbol tables
符号表第一部分
符号表第二部分
符号表:
原谅我直接引用
在计算机科学中,符号表是语言翻译器(如编译器或解释器)使用的数据结构,其中程序源代码中的每个标识符与源中的声明或外观相关的信息相关联,例如其类型,范围级别,有时它的位置。
也就是可以看变量的范围和类型
使用:
详细的见参考,这里完善下怎么让代码运行起来
symtable.symtable(code, filename, compile_type)
Return the toplevel SymbolTable for the Python source code. filename is the name of the file containing the code. compile_type is like the mode argument to compile().
code:[string] 文件的代码
filename: [string] 代码在哪个文件
compile_type:[string] 执行对象的类型(具体看compile())
运行可得:
也就可以看到变量 类型,是被引用还是全局等