2

I have seen this question, but I am having problems with the top solution. For example:

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

What am I doing wrong? Is this not supposed to work?

Community
  • 1
  • 1
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
  • Seems like a bug in their library...Do you need to get the quotes? – Michael Oct 12 '12 at 03:50
  • The scanf module appears to assume the quote is part of the string. It doesn't seem to handle %s followed by letters very well (that's a more complex parser). – Michael Oct 12 '12 at 16:26

1 Answers1

2

I wrapped the parse module:

from parse import parse
parse("\"%s\"".replace("%s","{}"), "\"test\"").fixed
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196