with open和open
时间: 2023-11-24 20:46:41 浏览: 83
with open和open的区别在于,使用with open可以自动关闭文件,而使用open需要手动关闭文件。with open的语法如下:
```
with open('file.txt', 'r') as f:
# do something with f
```
而open的语法如下:
```
f = open('file.txt', 'r')
# do something with f
.close()
```
阅读全文