您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python中的符号表

Python中的符号表

如果您询问生成字节码时使用的符号表,请看一下symtable模块。此外,Eli Bendersky撰写的这两篇文章非常有趣,而且非常详细:

Python内部构件:符号表,第1部分

Python内部构件:符号表,第2部分

在第2部分中,他详细介绍了一个可以打印出symtable描述的函数,但是它似乎是为Python 3编写的。这是Python 2.x的一个版本:

def describe_symtable(st, recursive=True, indent=0):
    def print_d(s, *args):
            prefix = ' ' *indent
            print prefix + s + ' ' + ' '.join(args)

    print_d('Symtable: type=%s, id=%s, name=%s' % (
            st.get_type(), st.get_id(), st.get_name()))
    print_d('  nested:', str(st.is_nested()))
    print_d('  has children:', str(st.has_children()))
    print_d('  identifiers:', str(list(st.get_identifiers())))

    if recursive:
            for child_st in st.get_children():
                    describe_symtable(child_st, recursive, indent + 5)
python 2022/1/1 18:42:31 有260人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶