我正在尝试使用pyparsing扫描文件。在pyparsing中有一个名为scanString的方法,它确实存在;
>>> name = pp.Word(pp.alphas)
>>> text = "**** Farcical aquatic ceremony"
>>> for result, start, end in name.scanString(text):
... print "Found {0} at [{1}:{2}]".format(result, start, end)
...
Found ['Farcical'] at [5:13]
Found ['aquatic'] at [14:21]
Found ['ceremony'] at [23:31]
但是我想用句子中的单词扫描一个txt文件。上面的scanString扫描单词中的单词。有没有办法扫描文件?或者,scanString只能像上面一样工作吗?