When testing my program, I keep getting this error:
1. Encrypt a file 2. Decrypt a file ----> 1 Enter the filename you'd like to encrypt: test Traceback (most recent call last): File "./encrypt.py", line 71, in <module> Main() File "./encrypt.py", line 58, in Main filename = input("Enter the filename you'd like to encrypt: ") File "<string>", line 1, in <module> NameError: name 'test' is not defined And here is my code for the Main() function:
def Main(): print("1. Encrypt a file") print("2. Decrypt a file") choice = str(input("----> ")) if choice == '1': filename = input("Enter the filename you'd like to encrypt: ") password = input("Enter a password used for the encryption tool: ") encrypt(getKey(password), filename) print("File has been encrypted.") elif choice == '2': filename = input("Enter the filename you'd like to decrypt: ") password = input("Enter the password used for the encryption of this file: ") decrypt(getKey(password), filename) print("File has been decrypted. Note that if the password used in the encryption does " \ + "not match the password you entered in, the file will remain encrypted.") else: print("Invalid option. Closing the program...") I am using the simple input() method to get my data ('test', for example), and it keeps telling me whatever information I enter in at runtime, the name of what I just entered is not defined. I don't see any formatting errors, syntax errors, etc.
inputinstead ofraw_inputon Python 2 and the top answer there is the clearest explanation I can find.