0

there. I apologize for the simple question, but I am a complete novice and need some help. I am trying to run Peter Norvig's Spelling Corrector (http://norvig.com/spell.py), but I'm receiving the following reply:

C:\>spelling.py
Traceback (most recent call last):
  File "C:\Python27\spelling.py", line 11, in <module>
    NWORDS = train(words(file('big.txt').read()))
IOError: [Errno 2] No such file or directory: 'big.txt'

The script includes an embedded text file (big.txt), which I've created and saved in the same directory as spelling.py. Why can't it find the big.txt file? Secondly, once the script is working, how would I use it against a sample of words needing correction?

1 Answer 1

3

The working directory of your script is the current folder, not the script's folder.

You can add the following code to your script to change this:

import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

Of course you could also use this folder only when opening the file instead of changing the working directory:

path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'big.txt')
NWORDS = train(words(file(path).read()))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.