如何使用Python摆脱文件中的标点符号?

时间:2015-09-08 03:38:06

标签: python file

def main():
   key = []

   mess=input('Write Text: ')

   for ch in mess:
       x = ord(ch)
       x = x-3
       x = chr(x)
       key.append(x)

   print("Your code message is: ", "".join(key))

   outFile = open("Encryptedmessage.txt","w")
   print(key, file=outFile)

main()

所以我写了这个。它消除了Python shell中的标点符号,但是当你开始阅读时,打开这样的文件仍然看起来像['q', 'e', 'b']而不是qeb。我怎样才能摆脱我制作的文件和Python shell中的标点符号。

1 个答案:

答案 0 :(得分:0)

key是一个数组,而不是一个字符串 你应该简单地将它打印成一个字符串 喜欢

   outFile = open("Encryptedmessage.txt","w")
   print("".join(key), file=outFile)