Python - TypeError:list indices必须是整数,而不是str

时间:2015-08-26 21:50:29

标签: list typeerror

我正在编写一个非常非常简单的加密脚本。

当我运行它时,发生了一个TypeError:

  

TypeError:list indices必须是整数,而不是str'

我查看了Stackoverflow上的一些问题,但没有任何帮助。

我认为这是一个非常简单的观点,我想念这里。

import os

os.system("clear")

content = input("content:" + " ")
filename = input("filename:" + " ")

content = list(content)
file = open(filename, "w")

counter = 0

os.system("clear")

input("Press enter to encrypt...")

for counter in content:
    if content[counter] in "a":
        content[counter] = "z"
    if content[counter] in "b":
        content[counter] = "y"
    if content[counter] in "c":
        content[counter] = "x"
    if content[counter] in "d":
        content[counter] = "w"
    if content[counter] in "e":
        content[counter] = "v"
    if content[counter] in "f":
        content[counter] = "u"
    if content[counter] in "g":
        content[counter] = "t"
    if content[counter] in "h":
        content[counter] = "s"
    if content[counter] in "i":
        content[counter] = "r"
    if content[counter] in "j":
        content[counter] = "q"
    if content[counter] in "k":
        content[counter] = "p"
    if content[counter] in "l":
        content[counter] = "o"
    if content[counter] in "m":
        content[counter] = "n"
    if content[counter] in "n":
        content[counter] = "m"
    if content[counter] in "o":
        content[counter] = "l"
    if content[counter] in "p":
        content[counter] = "k"
    if content[counter] in "q":
        content[counter] = "j"
    if content[counter] in "r":
        content[counter] = "i"
    if content[counter] in "s":
        content[counter] = "h"
    if content[counter] in "t":
        content[counter] = "g"
    if content[counter] in "u":
        content[counter] = "f"
    if content[counter] in "v":
        content[counter] = "e"
    if content[counter] in "w":
        content[counter] = "d"
    if content[counter] in "x":
        content[counter] = "c"
    if content[counter] in "y":
        content[counter] = "b"
    if content[counter] in "z":
        content[counter] = "a"

content = "".join(content)

file.write(content)
file.close()

os.system("clear")

print("Successfully encrypted!")
print("Use 'decrypt.py' to decrypt.")

0 个答案:

没有答案