我一直收到以下错误:
Traceback (most recent call last):
File "main.py", line 33, in <module>
main()
File "main.py", line 21, in main
translated = encrypt.encryptMess(mKey, content)
File "encrypt.py", line 7, in encryptMess
c = caesartranslate(content, mKey, myMode)
NameError: name 'myMode' is not defined
即使我已经在代码中定义了myMode。我检查了我的缩进,一切都是应该的。
import time, os, sys, encrypt, caesarCipher, reverseCipher, vigenereCipher, glob
def main():
inputFilename = 'frankensteinEnc.txt'
outputFilename = 'frankensteinEnc.encrypted.txt'
mKey = 5
myMode = 'encrypt'
if not os.path.exists(inputFilename):
print('The file %s does not exist. Exiting....' % (inputFilename))
sys.exit()
fileObj = open(inputFilename)
content = fileObj.read()
fileObj.close()
print ('%sing...' % (myMode.title()))
startTime = time.time()
if myMode == 'encrypt':
translated = encrypt.encryptMess(mKey, content)
elif myMode == 'decrypt':
translated = decrypt.decryptMess(mKey, content)
outputFileObj = open(outputFilename, 'w')
outputFileObj.write(translated)
outputFileObj.close()
print('Done %sing %s (%s characters).' % (myMode, inputFilename, len(content)))
print('%sed file is %s.' % (myMode.title(), outputFilename))
if __name__ == '__main__':
main()
我正在尝试使用caesar cipher,vigenere cipher和reverse cipher来获取加密文件的代码,但代码似乎停留在这三个错误上。请帮帮我
正如@be_good_do_good建议的那样,我改变了 translated = encrypt.encryptMess(mKey,content) 对此 translated = encrypt.encryptMess(mKey,content,myMode)
这是我的encrypt.py代码
from caesarCipher import *
from reverseCipher import *
from vigenereCipher import *
def encryptMess (mKey, content, myMode):
c = caesartranslate(content, mKey, myMode)
print('Output from Caesar Cipher\t%s') %c
c1 = reverse(c)
print('Output from Reverse Cipher\t%s') % c1
c2 = vtranslate(c1,c, myMode)
return('Output from Vigenere Cipher\t%s') % c2
在此之后我收到此追溯错误
Traceback (most recent call last):
File "main.py", line 33, in <module>
main()
File "main.py", line 21, in main
translated = encrypt.encryptMess(mKey, content, myMode)
File "encrypt.py", line 7, in encryptMess
print('Output from Caesar Cipher\t%s') %c
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
答案 0 :(得分:0)
您要么没有将myMode传递给encrypt.py
传递如下:
translated = encrypt.encryptMess(mKey, content, myMode)
并在encrypt.py中接收,如下所示
def encryptMess(mKey, content, myMode):
您发布的回溯清楚地表明,encrypt.py没有定义myMode
。 Atleast将myMode
定义为encrypt.py中的某个默认值(如'encrypt'或'decrypt')