py_ast.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:vizgen 作者: uva-graphics 项目源码 文件源码
def to_source_any(n):
    """
    Convert AST node to string, handling all node types, without fixing comments.
    """
    try:
        return astor.to_source(n)
    except AttributeError:
        pass
    cls = n.__class__
    if cls in astor.misc.all_symbols:
        return astor.misc.all_symbols[cls]
    def wrap(s):
        return '___' + s + '___'
    extra_d = {ast.Load: wrap('load'),
               ast.Store: wrap('store'),
               ast.Del: wrap('del'),
               ast.AugLoad: wrap('augload'),
               ast.AugStore: wrap('augstore'),
               ast.Param: wrap('param'),
               ast.keyword: wrap('keyword')}
    if cls in extra_d:
        return extra_d[cls]
    raise AttributeError('unknown node type {}'.format(cls))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号