2012-10-12 34 views
1

我看过this question,但我在top solution有问题。 例如:为python工作sscanf(最好是py3k)?

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

我在做什么错?这不应该工作吗?

+0

好像在他们的库中的缺陷...你需要获得报价? – Michael

+0

@迈克尔:是的,我做 –

+0

scanf模块似乎假设报价是字符串的一部分。它似乎无法处理%s,后面紧跟字母(这是更复杂的解析器)。 – Michael

回答

1

我包the parse module

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