definiert Wenn mein Programm zu testen, halte ich immer diese Fehlermeldung:Nameerror: name '[string]' ist nicht
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
Und hier ist mein Code für die Main() Funktion:
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...")
Ich verwende die einfache Methode input(), um meine Daten zu erhalten (zum Beispiel 'test'), und sie teilt mir ständig die Informationen mit, die ich zur Laufzeit eingegeben habe. Der Name der gerade eingegebenen Daten ist nicht definiert. Formatierungsfehler, Syntaxfehler usw. werden nicht angezeigt.
Welches Python-Version ist das? – Mureinik
Mögliches Duplikat von [unerwartetes Python-EOF beim Parsen] (http://stackoverflow.com/questions/5074225/python-unexpected-eof-while-parsing) –
Ich weiß, dass das wie ein komischer Betrogener aussieht, aber ich vermute stark, dass Sie verwenden 'input' anstelle von' raw_input' in Python 2 und die oberste Antwort dort ist die klarste Erklärung, die ich finden kann. –