Search code examples
linuxpython-3.4python-interactiveinteractive-mode

Python3 interactive mode on Linux launches the codes twice


I have written a chess program in Python 3.4.3 and I am running the Python 3 interpreter in the interactive mode as follows:

python3 -i chess.py

However, the code after the class definitions get invoked twice and I do not know why. My code is on pastebin


Solution

  • You should remove the line from chess import * that is at the end of the file, it should not be needed.

    Also, it is common to make sure that some of the code is not executed unless the code in the module is executed as a script.

     if __name__ == '__main__':
         # Not executed if the module is imported
         g = Game()