工作sscanf的Python的(最好是py3k)?(Working sscanf for Pyth

2019-09-24 01:02发布

我已经看到了这个问题 ,但我有问题的顶级解决方案 。 例如:

>>> scanf.sscanf("\"test\"","\"%s\"")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "scanf.py", line 393, in sscanf
    return bscanf(CharacterBufferFromIterable(inputString), formatString)
  File "scanf.py", line 414, in bscanf
    return parser(buffer)
  File "scanf.py", line 577, in __call__
    raise IncompleteCaptureError(e, tuple(results))
scanf.IncompleteCaptureError: (FormatError('" != ',), ('test"',))
>>> 

我究竟做错了什么? 难道这不应该工作?

Answer 1:

我包解析模块 :

from parse import parse
parse("\"%s\"".replace("%s","{}"), "\"test\"").fixed


文章来源: Working sscanf for Python (preferrably py3k)?