使用Python的sscanf(最好是py3k)?

时间:2012-10-12 02:38:29

标签: python printf scanf

我见过this question,但我遇到top solution的问题。 例如:

>>> 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"',))
>>> 

我做错了什么?这不应该有用吗?

1 个答案:

答案 0 :(得分:1)

我包裹了the parse module

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