であっても、私は、次のエラーを取得し続ける:グローバル名エラーが定義されていないことが
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()
私は、シーザー暗号を使用してファイルを暗号化するためのコードを取得ヴィジュネル暗号と暗号を逆転しようとしていますが、コードは、これらの3つのエラーに引っかかっているように見えます。 @be_good_do_goodが示唆したように私に
を助けてください、私は
この 翻訳= encrypt.encryptMess(MKEY、コンテンツ、はMyMode)に 翻訳= encrypt.encryptMess(MKEY、コンテンツ) を変更し、これが私の暗号化です.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'
あなたのコードは正しくインデントされているかもしれませんが、質問のコードは確かに表示されないので、 。 –
また、 "encrypt.py"ファイルも含まれています。これは標準ライブラリではありません。 –
'myMode'は' main() '関数のローカルな変数なので、' encrypt.py'モジュールのコードからアクセスできません。その中にある呼び出し可能なものへの引数。 Pythonの "global"は一般的に、モジュール間の** ** **の項目を定義するモジュール内にあることを意味します。 – martineau