微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python pyparsing 模块-White() 实例源码

Python pyparsing 模块,White() 实例源码

我们从Python开源项目中,提取了以下1代码示例,用于说明如何使用pyparsing.White()

项目:gtool    作者:gtoolframework    | 项目源码 | 文件源码
def compute(self):

        def getname(obj, name):

            _val = None

            if hasattr(obj, name):
                _val = getattr(obj, name, None)

            if _val is None:
                return _val

            try:
                if _val.isdynamic: #Todo make this work for non-attributes,non-dynamics (use .issingleton? - what about a concat mode?)
                    raise ValueError('Combine plugin cannot process %s because it contains a dynamic class' % name)
            except AttributeError:
                raise TypeError('Expected an attribute but got a %s' % type(_val))

            if _val.issingleton():
                _ret = '%s' % _val[0].raw()
            else:
                _ret = ','.join(['%s' % v.raw() for v in _val])

            return _ret

        attrmarker = (p.Literal('@') | p.Literal('!'))
        attrmatch = attrmarker.suppress() + p.Word(p.alphanums)

        for i in attrmatch.scanString(self.config):
            x = i[0][0]
            self.__attribs__[x] = getname(self.targetobject, x)

        if all(v is not None for v in self.__attribs__.values()):
            self.computable = True

        if self.computable:

            attrmatch = p.Literal('@').suppress() + p.Word(p.alphanums)
            attrmatch.setParseAction(self.substitute)
            attrlist = p.ZeroOrMore(p.Optional(p.White()) + attrmatch + p.Optional(p.White()))

            self.__result__ = attrlist.transformString(self.config)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐