util.py 文件源码

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

项目:deb-python-pint 作者: openstack 项目源码 文件源码
def eval_token(cls, token, use_decimal=False):
        token_type = token.type
        token_text = token.string
        if token_type == NUMBER:
            try:
                return int(token_text)
            except ValueError:
                if use_decimal:
                    return Decimal(token_text)
                return float(token_text)
        elif token_type == NAME:
            return ParserHelper.from_word(token_text)
        else:
            raise Exception('unknown token type')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号