TypeError: 'str' does not support the buffer interface

后端 未结 7 799
南方客
南方客 2020-11-22 03:11
plaintext = input(\"Please enter the text you want to compress\")
filename = input(\"Please enter the desired filename\")
         


        
7条回答
  •  囚心锁ツ
    2020-11-22 03:57

    There is an easier solution to this problem.

    You just need to add a t to the mode so it becomes wt. This causes Python to open the file as a text file and not binary. Then everything will just work.

    The complete program becomes this:

    plaintext = input("Please enter the text you want to compress")
    filename = input("Please enter the desired filename")
    with gzip.open(filename + ".gz", "wt") as outfile:
        outfile.write(plaintext)
    

提交回复
热议问题