好吧,我已经挣扎了好几天了。我被指派去做一个代码,上面写着密码.py导入加密文本文件的密钥.txt要解密,请将解密的信息写入解密.txt““
我一直收到加密字=加密字.replace(str(加密文件[i][1]),str(解密文件[i][0])) AttributeError:“list”对象没有“replace”属性
你知道吗?你知道吗
key = open("key.txt", "r")
encrypted = open("encrypted.txt","r" )
decrypted = open("decrypted.txt", "w")
encryptedFiles = []
decryptedFiles = []
unencrypt= ""
for line in key:
linesForKey = line.split()
currentEncrypted = (line[0])
currentDecrypted = (line[1])
encryptedFiles.append(currentEncrypted)
decryptedFiles.append(currentDecrypted)
key.close()
##########################################
encryptedWords = []
encryptedString = ""
lines = encrypted.readlines()
for line in lines:
letter = list(line)
encryptedWords += letter
for i in range(len(encryptedWords)):
encryptedWords = encryptedWords.replace(str(encryptedFiles[i][1]),str(decryptedFiles[i][0]))
encrypted.close()
decrypted.write(encryptedWords)
decrypted.close()
The ^{} attribute is only for strings 。如我所见,您可以将
+=
添加为字符串。你知道吗+=
有趣的是,ing使用列表:+=
接受字符串,拆分必须与list(string)
一样。与此相反,您可以将encryptedWords
更改为字符串(encryptedWords = ''
),也可以使用''.join(encryptedWords)
或' '.join(encryptedWords)
转换回您想要的字符串:相关问题 更多 >
编程相关推荐