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