我有我想要運行的以下python腳本。 但是,每當我嘗試運行腳本時,它都會在我的命令提示符上不斷顯示錯誤消息。 錯誤消息:Python腳本,語法錯誤,無效語法
File "xor.py", line 9
File = open(sys.argv[1], 'rb').read<>
SyntaxError: Invalid Syntax
以下是我在cmd中執行的命令:
python xor.py sample_output.txt 'what would the secret be?'
下面是腳本:
# xor.py
import sys
from itertools import cycle
file = open(sys.argv[1], 'rb').read()
string = sys.argv[2]
sys.stdout.write(''.join(chr(ord(x)^ord(y)) for (x,y) in zip(file, cycle(string))))
代碼'文件=打開(SYS。 argv [1],'rb')。read()'但是錯誤說'File = open(sys.argv [1],'rb')。read()'。爲什麼? – thefourtheye
請不要用變量影射內建函數,'file'和'string'對變量名都是不好的選擇。 – Kimvais
添加您正在運行的確切代碼;如果這是您正在運行的代碼 - 刪除名爲'xor.pyc'的文件(它將位於與'xor.py'相同的目錄中)並再次嘗試。 –