【发布时间】:2015-05-04 12:03:49
【问题描述】:
我正在尝试制作一个程序,允许用户输入数据以指定文件名和扩展名,然后压缩该文件并允许他们命名。但是我不断收到错误消息“需要一个整数(得到类型 str),它说它与 'rb' 点有关。有关如何解决此问题的任何信息?
import zlib
first_answer = input("Please input file name")
print(first_answer)
second_answer = input("Please input file extension")
with open(first_answer, ".", second_answer, 'rb') as in_file:
compressed = zlib.compress(in_file.read(), 9)
third_answer = input("What would you like to call this new file?")
with open(third_answer, "wb") as out_file:
out_file.write(compressed)
print("File has been compressed!")
【问题讨论】:
标签: python python-3.x compression