How To Run Peter Norvig's Spell Checker In PyCharm?

I downloaded PyCharm today.  I need help getting off the dime with the simplest of problems.

I created a new project and created a new file SpellChecker.py.  I pasted Peter Norvig's brilliant Python spell checker into it and saved it.  I also downloaded the "big.txt" Project Gutenberg seed file and put it right at the project root.  If I add a breakpoint and run in debug mode, I can see that the train method is invoked, the seed file is read properly, and the NWORDS dictionary is populated.  So far, so good.

I opened a Python console and typed "import SpellChecker".  All was well.  I thought that would allow me to invoke methods on SpellChecker, so I typed "correct('wurd') at the command prompt and expected to get back 'spelling'.  Instead, I got an error message:

C:\Tools\Python-2.6.1\python.exe -u C:\Program Files\JetBrains\PyCharm 96.742\helpers\pydev\console\pydevconsole.py 3833 3834

import sys; print('Python %s on %s' % (sys.version, sys.platform))

Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32

sys.path.append('C:/Documents and Settings/Michael/My Documents/Projects/Python/norvig-spell-check')

>>> import SpellChecker

>>> correct('wurd')

Traceback (most recent call last):

  File "<console>", line 1, in <module>

NameError: name 'correct' is not defined

What did I miss?  What's the correct way to call methods on the SpellChecker?  I'll confess that I'm a noob at both Python and PyCharm, so I'm hoping that my error will be completely obvious.  Thanks.

1 comment

Sorry, now I see it: SpellChecker.correct('wurd') gives me what I need. 

0

Please sign in to leave a comment.