我是python的新手,正在使用mincemeat处理map问题。运行mincemeat脚本时出现以下错误。全局名称're'未定义
$python mincemeat.py -p changeme localhost
error: uncaptured python exception, closing channel <__main__.Client connected at 0x923fdcc>
(<type 'exceptions.NameError'>:global name 're' is not defined
[/usr/lib/python2.7/asyncore.py|read|79]
[/usr/lib/python2.7/asyncore.py|handle_read_event|438]
[/usr/lib/python2.7/asynchat.py|handle_read|140]
[mincemeat.py|found_terminator|96]
[mincemeat.py|process_command|194]
[mincemeat.py|call_mapfn|170]
[raw1.py|mapfn|43])
我的代码停留在其在上述堆栈跟踪给定为[raw1.py|mapfn|43]
raw1.py脚本。
import re
import mincemeat
# ...
allStopWords = {'about':1, 'above':1, 'after':1, 'again':1}
def mapfn(fname, fcont):
# ...
for item in tList[1].split():
word = re.sub(r'[^\w]', ' ', item).lower().strip() # ERROR
if (word not in allStopWords) and (len(word) > 1):
# ....
我已经在raw1.py中导入了re
。如果我在mincemeat.py中导入re
,则不会出现该错误。
万岁,很高兴在coursera的大数据课程中看到同学。 – RAbraham