我似乎有一个非常奇怪的错误。下面的代码工作了两三次,然后以 TypeError 结束
cmd = "perl prog.pl"
process = Popen(shlex.split(cmd), stdout=PIPE)
matchstr=process.communicate()
exit_code = process.wait()
print exit_code
embedded_rawstr = r"""Extract"(?P<ex>.*?)".*?"""
print re.findall(embedded_rawstr, matchstr)
该代码在循环中被调用,因此它被频繁地调用。为什么会发生此错误,我该如何解决?
Traceback (most recent call last):
File "ga-test.py", line 122, in <module>
main()
File "ga-test.py", line 65, in main
fitnesses = list(map(toolbox.evaluate, pop))
File "ga-test.py", line 47, in evalOneMax
print re.findall(embedded_rawstr, matchstr)
File "C:\Python27\lib\re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer