私は名前と年齢のファイルを持っています、
john 25
bob 30
john bob 35
これが私がこれまでに持っているものです
from pyparsing import *
data = '''
john 25
bob 30
john bob 35
'''
name = Word(alphas + Optional(' ') + alphas)
rowData = Group(name +
Suppress(White(" ")) +
Word(nums))
table = ZeroOrMore(rowData)
print table.parseString(data)
私が期待している出力は
[['john', 25], ['bob', 30], ['john bob', 35]]
これがスタックトレースです
Traceback (most recent call last):
File "C:\Users\mccauley\Desktop\client.py", line 11, in <module>
eventType = Word(alphas + Optional(' ') + alphas)
File "C:\Python27\lib\site-packages\pyparsing.py", line 1657, in __init__
self.name = _ustr(self)
File "C:\Python27\lib\site-packages\pyparsing.py", line 122, in _ustr
return str(obj)
File "C:\Python27\lib\site-packages\pyparsing.py", line 1743, in __str__
self.strRepr = "W:(%s)" % charsAsStr(self.initCharsOrig)
File "C:\Python27\lib\site-packages\pyparsing.py", line 1735, in charsAsStr
if len(s)>4:
TypeError: object of type 'And' has no len()