本文介绍了为 Python(最好是 py3k)工作 sscanf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
>>>scanf.sscanf("\"测试\"","\"%s\"")回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中文件scanf.py",第 393 行,在 sscanf 中返回 bscanf(CharacterBufferFromIterable(inputString), formatString)文件scanf.py",第 414 行,在 bscanf 中返回解析器(缓冲区)文件scanf.py",第 577 行,在 __call__ 中引发 IncompleteCaptureError(e, tuple(results))scanf.IncompleteCaptureError: (FormatError('" != ',), ('test"',))>>>我做错了什么?这不应该工作吗?
解决方案
我封装了解析模块:
from parse import parseparse("\"%s\"".replace("%s","{}"), "\"test\""). 已修复
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?
解决方案
I wrapped the parse module:
from parse import parse
parse("\"%s\"".replace("%s","{}"), "\"test\"").fixed
这篇关于为 Python(最好是 py3k)工作 sscanf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!