本文整理汇总了Python中pyparsing.ZeroOrMore.setWhitespaceChars方法的典型用法代码示例。如果您正苦于以下问题:Python ZeroOrMore.setWhitespaceChars方法的具体用法?Python ZeroOrMore.setWhitespaceChars怎么用?Python ZeroOrMore.setWhitespaceChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.ZeroOrMore
的用法示例。
在下文中一共展示了ZeroOrMore.setWhitespaceChars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Literal
# 需要导入模块: from pyparsing import ZeroOrMore [as 别名]
# 或者: from pyparsing.ZeroOrMore import setWhitespaceChars [as 别名]
from pyparsing import Word, Literal, LineEnd, ZeroOrMore, OneOrMore, Regex, \
Group, ParseException, ParseSyntaxException, Combine, \
restOfLine, alphas, alphanums, delimitedList, nums
comma = Literal(',').suppress().setName('comma')
semicolon = Literal(';').suppress().setName('semicolon')
decimal = Combine(Word(nums).setName('number') + '.' + Word(nums)).setName('decimal') | \
Word(nums).setName('decimal')
decimal.setParseAction(lambda s,l,t: [Decimal(t[0]).normalize()])
comment = Literal('#') + restOfLine
name = Word(alphas + "_", alphanums + "_").setName('name')
names = Group(delimitedList(name)).setName('names')
entry = name - semicolon - names - semicolon - decimal - LineEnd().suppress()
entry.setParseAction(lambda s,l,t: [(t[0],set(t[1]),t[2])])
parser = ZeroOrMore(entry | LineEnd().suppress())
parser.setWhitespaceChars(r' \t\f').ignore(comment)
def parse(s):
return parser.parseString(s, parseAll=True)
def getPersons(p):
ret = set()
for (creditor, debtors, _) in p:
ret.add(creditor)
ret |= debtors
return ret
def getDebtsFor(p, debtor):
ret = {}
for person in getPersons(p): ret[person] = 0
for (creditor, debtors, amount) in p: