当前位置: 首页>>代码示例>>Python>>正文


Python Suppress.searchString方法代码示例

本文整理汇总了Python中pyparsing.Suppress.searchString方法的典型用法代码示例。如果您正苦于以下问题:Python Suppress.searchString方法的具体用法?Python Suppress.searchString怎么用?Python Suppress.searchString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing.Suppress的用法示例。


在下文中一共展示了Suppress.searchString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_puppetfile_forge_mods

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import searchString [as 别名]
    def parse_puppetfile_forge_mods(cls, file_contents):
        mod_kwargs = {}
        quotedString = QuotedString('"') ^ QuotedString('\'')

        forge_url_grammar = Suppress('forge') + quotedString
        for url, in forge_url_grammar.searchString(file_contents):
            mod_kwargs['forge_url'] = url

        mod_grammar = Suppress('mod') + quotedString + Suppress(',') + quotedString
        mods = mod_grammar.searchString(file_contents)
        for mod, version in mods:
            user, mod_name = mod.split('/')
            yield cls(user, mod_name, version, **mod_kwargs)
开发者ID:mayflower,项目名称:pumuckl,代码行数:15,代码来源:module.py

示例2: parse_grd_file

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import searchString [as 别名]
    def parse_grd_file(self):
        global __line

        try:
            f = open(self.grd_file, 'r')
        except:
            raise

        for j in range(0, 6):
            __line = f.next()

        (self.nx, self.ny) = map(int, __line.split())

        print "Grid file %s (%d, %d)" % (self.grd_file, self.nx, self.ny)

        f.close()

        floatNumber = Regex(r'-?\d+(\.\d*)?([eE][\+-]\d+)?').setParseAction(lambda s, l, t: [float(t[0])])
        integer = Word(nums).setParseAction(lambda s, l, t: [long(t[0])])
        grdline = Suppress('ETA=') + Suppress(integer) + OneOrMore(floatNumber)

        for a in grdline.searchString(file(self.grd_file).read()):
            if len(self.x) < self.ny:
                self.x.append(a.asList())
            else:
                self.y.append(a.asList())
开发者ID:mvrk,项目名称:BACKUP,代码行数:28,代码来源:models.py

示例3: get_network_name

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import searchString [as 别名]
    def get_network_name(self):
        """
        Retruns the name of the network

        Example
        ---------------
        >>> from pgmpy.readwrite import BIFReader
        >>> reader = BIF.BifReader("bif_test.bif")
        >>> reader.network_name()
        'Dog-Problem'
        """
        start = self.network.find('network')
        end = self.network.find('}\n', start)
        # Creating a network attribute
        network_attribute = Suppress('network') + Word(alphanums + '_' + '-') + '{'
        network_name = network_attribute.searchString(self.network[start:end])[0][0]

        return network_name
开发者ID:MariosRichards,项目名称:BES_analysis_code,代码行数:20,代码来源:BIF.py

示例4: main

# 需要导入模块: from pyparsing import Suppress [as 别名]
# 或者: from pyparsing.Suppress import searchString [as 别名]
def main(argv):
    """
    """
    group = OptionGroup("example", "OptionGroup Example", \
        "Shows all example options",
        option_list = [
            make_option("--example",
                        action="store_true",
                        dest="example",
                        help="An example option."),
        ]
    )

    parser = OptionParser("NAMES ...",
        description="A simple gobject.option example.",
        option_list = [
            make_option("--file", "-f",
                        type="filename",
                        action="store",
                        dest="file",
                        help="A filename option"),
            # ...
        ])

    parser.add_option_group(group)

    parser.parse_args()
    
    lineBody = SkipTo(lineEnd).setParseAction(mustBeNonBlank)

    # now define a line with a trailing lineEnd, to be replaced with a space character
    textLine = lineBody + Suppress(lineEnd).setParseAction(replaceWith(" "))

    # define a paragraph, with a separating lineEnd, to be replaced with a double newline
    para = OneOrMore(textLine) + Suppress(lineEnd).setParseAction(replaceWith("\n\n"))

    # run a test
    test = """
        Now is the
        time for
        all
        good men
        to come to

        the aid of their
        country.
    """
    print para.transformString(test)

    subdir_dir = Word(alphas, alphanums+"_")
    #macroDef = Suppress("SUBDIRS") + Suppress("=") + restOfLine
    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=True )
    macros = list(subdir_dir_list.searchString(subdirs_1line))
    print("1: subdirs of subdirs_1line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=True )
    macros = list(subdir_dir_list.searchString(subdirs_2line))
    print("2: subdirs of subdirs_2line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=False)
    macros = list(subdir_dir_list.searchString(subdirs_2line))
    print("2: subdirs of subdirs_2line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + \
        delimitedList( subdir_dir, " ", combine=False) + \
        Suppress(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_3line))
    print("3: subdirs of subdirs_3line are {}".format(macros))

    # This returns a list!
    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + \
        delimitedList( subdir_dir, " ", combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_3line))
    print("3: subdirs of subdirs_3line are {}".format(macros))

    # This returns nothing because SUBDIRS is commented out!
    subdir_dir_list = Suppress(lineStart) + Suppress("SUBDIRS") + \
        Suppress("=") + delimitedList( subdir_dir, " ", combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_4line))
    print("4: subdirs of subdirs_4line are {}".format(macros))

    # This returns 
    subdir_dir_list = Suppress(lineStart) + Suppress("SUBDIRS") + \
        Suppress("=") + delimitedList( subdir_dir, OneOrMore(" "), combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_5line))
    print("5: subdirs of subdirs_5line are {}".format(macros))
    print("5a: subdirs of subdirs_5line are {}".\
        format(subdir_dir_list.scanString(subdirs_5line)))

    print "group: example ", group.values.example
    print "parser: file", parser.values.file

    res = 1
    try:
        pyparsing()
        print('{}'.format("pyparsing() done."))
        lun_q = r'''Lun:\s*(\d+(?:\s+\d+)*)'''
#.........这里部分代码省略.........
开发者ID:agander,项目名称:gander,代码行数:103,代码来源:rerun_autoconf.py


注:本文中的pyparsing.Suppress.searchString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。