简单的说,
with open(filepath, 'wb') as file: file.write("something")
等价于:
file = open(filepath) try: file.write("something", 'wb') finally: file.close()
总的来说with... as包含一个错误处理和一个文件关闭功能!