0

I am trying to deploy a Python/Flask application to PythonAnywhere, but I am receiving a, "Something went wrong" error. After checking the error log, I found this message, "FileNotFoundError: [Errno 2] No such file or directory: 'words.txt'". I have a word.txt file in my application which contains various different words (I am using it as a dictionary that my application reads from) and want to know how I can deploy a .txt file from PythonAnywhere? Every other file/folder that I upload seems to be accepted.

Here is my code:

Python

class Boggle():

    def __init__(self):

        self.words = self.read_dict("words.txt")

    def read_dict(self, dict_path):
        """Read and return all words in dictionary."""

        dict_file = open(dict_path)
        words = [w.strip() for w in dict_file]
        dict_file.close()
        return words

    def make_board(self):
        """Make and return a random boggle board."""

        board = []

        for y in range(5):
            row = [choice(string.ascii_uppercase) for i in range(5)]
            board.append(row)

        return board

    def check_valid_word(self, board, word):
        """Check if a word is a valid word in the dictionary and/or the boggle board"""

        word_exists = word in self.words
        valid_word = self.find(board, word.upper())

        if word_exists and valid_word:
            result = "ok"
        elif word_exists and not valid_word:
            result = "not-on-board"
        else:
            result = "not-word"

        return result

Also here is a screenshot of my directory Photo of project directory

As you can see, the, "word.txt" file is in the root of the directory.

rudehlabya
  • 109
  • 1
  • 8
  • 1
    You'll need to show some code, and state the exact location of that `words.txt` file for any worthwhile answer on this. – v25 Nov 28 '20 at 19:50
  • @v25 Thanks. I will make those updates. – rudehlabya Nov 28 '20 at 19:57
  • 1
    From that screencap and your code it looks like this should work. Perhaps try the [fix mentioned here](https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/). – v25 Nov 28 '20 at 21:21

0 Answers0