Search code examples
pythonpython-3.xcx-freeze

Console input not evaluating correctly with python script built into an exe with cx_freeze


I have a script consisting of 3 files and 2 packages. When I run the script in IDLE or via the command line, it executes perfectly. I used cx_freeze to convert the program to an executable, and it still works fine except for text recieved via the input() method is evaluating wrong. This code mirrors my own:

x = str(input("Continue? (y/n): "))
if x.lower() == "y" or x.lower() == "yes":
    cont = True
else:
    print("thanks for playing.")
    cont = False
input("press enter key to exit...")

I added the str() converter to the input function to see if it would help, but it didn't. No matter if I type "yes" or "y", the conditional still evaluates to false, and I have no idea why. I also added print statements to each branch of the conditional, and the value printed for x is correct, yet it still evaluates false.


Solution

  • Sometimes the input gets a newline character on the end. Try stripping it:

    x = input("Continue? ").strip()