我在Python和编程方面是个半文盲,但是当我双击打开.py文件时,我的程序就不能正常工作了。当我通过IDE(Pycharm)从命令行运行它时,它就会出现。基本上,当双击时,它将到达key=input(“Enter-decode key:”)部分,键入内容后,它将关闭。任何帮助都将不胜感激。我知道我的代码并不优雅,它只是需要工作。Python 3.5.2
如果有帮助,“key”的示例输入将是23,而“encoded”的示例输入是142128133123134142。它应该输出“window”,并在命令行和Pycharm中成功输出。在import sys
def main(key, encoded):
if encoded == 0: #This should run if program was double-clicked (no arguments)
encoded = input("Paste encoded JavaScript: ")
key = input("Enter decode key: ")
def decode(key, encoded): #Decode the data
encoded = encoded.split(',') #Split each section delimiting by a colon
decoded = []
for x in encoded:
x = int(x) - int(key) #Subtract the key from the number in each section
decoded.append(chr(x)) #Change from ASCII decimal code to the ASCII character
decoded = ''.join(decoded) #Join back into a string
print(".")
print(".")
print(".")
print(".")
print("Encoded data:")
print(encoded)
print("Decode key:")
print(key)
print("Decoded data:")
print(decoded)
return 0
decode(key, encoded) #Jump into the decode function
return 0
if __name__ == "__main__":
try:
if len(sys.argv) > 1: #If length is greater than 1, then there were arguments added upon program execution
key = sys.argv[1] #The "key" should be the first argument
encoded = sys.argv[2] #The "encoded" data should follow
else:
key = 0 #If length is anything else, then set them to 0 and ask for the data later
encoded = 0
main(key, encoded) #Jump into main function and pass the key and encoded arguments
finally:
input("Press Enter to exit")