def main():
inFile = open ('input.txt', 'r')
fileContent = inFile.read()
choice = input('Do you want to encrypt or decrypt? (E / D): ')
for i in fileContent:
if (choice == 'E'):
for i in range(0, len(str), 2):
even_str = str[i]
for i in range(1, len(str), 2):
odd_str = str[i]
outFile = open("output.txt", "w")
outFile.write(even_str)
outFile.write(odd_str)
outFile.write(encrypted_str)
print('even_str = ',even_str)
print('odd_string = ',odd_str)
print('encrypted_str = ',encrypted_str)
outfile.close()
if (choice != 'E' and choice != 'D'):
print ('')
print ('Wrong input. Bye.')
return
inFile.close()
main()尝试加密字符串并将奇数和偶数字符加在一起,但我一直收到此错误。我设置了一个要测试的文件,但它似乎无法工作。
Traceback (most recent call last):
File "C:/Python33/CS303E/Cipher.py", line 41, in <module>
main()
File "C:/Python33/CS303E/Cipher.py", line 24, in main
for i in range(0, len(str), 2):
TypeError: object of type 'type' has no len()发布于 2014-04-05 11:17:22
当您应该使用fileContent (包含输入字符串的变量的名称)时,您可以继续使用str (表示字符串的类型的名称)。
发布于 2014-04-05 11:16:55
str是一种类型(字符串,你也可以把它看作是构造函数),它是语言的一部分,你没有这样的变量。也许你想要这样的东西:
for i in range(0, len(fileContent), 2):https://stackoverflow.com/questions/22876122
复制相似问题