Alex Rivera | Logout

global name 're' is not defined

Asked 2012-10-04T10:12:12.460
13

I am new to python and working on a map reduce problem with mincemeat. I am getting the following error while running the mincemeat script.

$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])

My code rests in raw1.py script which is given in the above stacktrace as [raw1.py|mapfn|43].

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):
            # ....

I have already imported re in raw1.py. The error doesn't appear if I import re in mincemeat.py.

Edit
Report

1 Answer

0

It sounds like you've already answered this question. If you use re in mincemeat.py, you'll need to import re there as well.

answered 2012-10-04T10:17:15.703

Your Answer