python-4-之with和open对比
来源:互联网 发布:淘宝定时上架怎么抢 编辑:程序博客网 时间:2024/05/29 18:48
open和file方法类似
打开文件使用后,要确保关闭,才是安全的:
#open your file heretry: #write data to your filefinally: file.close()
try: f=open('test.txt','r')except: passelse: babababbabafinally: f.close()
相比之下,with语句简洁许多,而且自带关闭
with open("somefile.txt") as somefile:do_something(somefile)
with open('abc.txt','r') as f: print 'babababa'
阅读全文
0 0
- python-4-之with和open对比
- python之with open as
- Python 之 open() 和file()
- python with open
- Python With Open
- Python with open语句
- open source ids with python
- python os.open() 和open()
- 对比java和python对比
- python之open()函数
- python的with open as f
- eoprocessing with Python using Open Source GIS
- python文本读写,with open as
- 用with open完成python读写
- python和ruby对比
- Jython 和 Python 对比
- java和python对比
- 对比java和python
- CTS Verifier
- web 项目 jsp加载applet
- maven添加本地jar包
- [Usaco2007 Dec]Building Roads 修建道路
- 比较当前时间和给定时间大小
- python-4-之with和open对比
- 如何配置crontab定时删日志数据
- GIT与SVN的区别以及SVN转GIT
- Ruby 工具库
- 射频识别技术漫谈(1)——概念、分类
- 欢迎使用CSDN-markdown编辑器
- 初学数据仓库--简单概念
- Nginx下出现Access denied (403) see security.limit_extensions错误的解决方法
- CodeCreater-代码生成器