0

Basically, I'm editing a battleship code so that you can save the board at any point in the game by writing it to a file. However, when I write it to the file, the only thing that is in the file is the word "None". These are the two chunks I've added.

def save_game():
    with open('savegame.txt', 'w') as f:
        f.write(str(print_board(board, True)))

. . . .

    finally:
        if str(position) == 'save':
            save_game()
            return print_board(board, reveal = False)
            exit()
  • This means that `print_board()` doesn't return anything. From the name, it sounds like it prints the board, it doesn't return the printed representation of the board. – Barmar Dec 09 '22 at 00:56
  • I bet `print_board()` returns `None`. So you might find your answer here: [What is the purpose of the return statement? How is it different from printing?](/q/7129285/4518341) There are a lot of similar questions too; just google `python print vs return`. – wjandrea Dec 09 '22 at 00:56

0 Answers0