有没有办法在 pyparsing 中使用数字?
我正在 python 3.8 中使用 python 库 PyParsing,我想知道是否有办法解析数字?这是我当前的代码:
from pyparsing import Word, alphas
getWordParse = Word(alphas)
alphas
只是字符,是否也可以使用数字?
I am using the python library PyParsing in python 3.8, and I am wondering if there is a way to parse numbers? Here is my current code:
from pyparsing import Word, alphas
getWordParse = Word(alphas)
alphas
is only characters, would there be a way to use numbers as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

Pyparsing 提供了几个用于定义 Word 的方便常量:
但这些都只是字符串,您也可以使用字符串文字定义 Word:
打印:
Pyparsing 还包括一些常见表达式的解析器(例如
integer
、real
、fnumber
和number
),其中还包括解析操作,这些操作会将解析结果返回为 int 或 float,而不仅仅是 str。这是一个很好的“入门”文档页面: https://pyparsing-docs .readthedocs.io/en/latest/HowToUsePyparsing.html
这是 Word 的参考页面:https://pyparsing-docs.readthedocs.io/ en/latest/pyparsing.html?highlight=Word#pyparsing.Word
请访问 pyparsing wiki 以获取更多信息:https://github.com/pyparsing/pyparsing/wiki
Pyparsing provides several convenience constants for defining Word's:
But these are all just strings, and you can define Words using string literals too:
Prints:
Pyparsing also includes some parsers for common expressions (like
integer
,real
,fnumber
, andnumber
), which also include parse actions that will returned the parsed results as ints or floats, instead of just strs.Here is a good "getting started" docs page: https://pyparsing-docs.readthedocs.io/en/latest/HowToUsePyparsing.html
And here is the reference page on Word: https://pyparsing-docs.readthedocs.io/en/latest/pyparsing.html?highlight=Word#pyparsing.Word
Visit the pyparsing wiki for more info at: https://github.com/pyparsing/pyparsing/wiki