是否有将python'with'语句转换为可以在以前版本的python中使用的格式的方法。关于这个问题的4个月的工作。与之前的同行相比效率更高,但效率在这里并不重要。'With'in pre python 2.5
0
A
回答
3
0
正如S.Lott所说,试着最后应该处理with子句的工作。我不知道,其实with
捕捉任何错误,所以考虑到假设:
with open(file_name,mode) as name: # Or whatever expression
do_this()
可以
try:
name = open(filename,mode) # Or whatever expression
do_this()
finally:
name.close()
相关问题
- 1. If/Else Statement and Lists Within Functions - Python 3.x
- 2. IFERROR STATUS WITHIN VLOOKUP
- 3. like within查询
- 4. Python 2.5和Tskill
- 5. PyQt和Python 2.5
- 6. python 2.5日期?
- 7. For Matlab within Matlab GUIDE
- 8. UPDATE使用WITHIN GROUP
- 9. This Keywords * within * Javascript Module
- 10. while while loops within expected
- 11. removeChild not working within stringByEvaluatingJavaScriptFromString
- 12. with statement - Python for Python 2.5
- 13. 大小在Python 2.5
- 14. MySQL中的Python 2.5
- 15. Python中的namedtuple 2.5
- 16. Python 2.5:IO模块
- 17. 可以用Python 2.5
- 18. Python 2.5 zlib麻烦
- 19. Python 2.5的编码
- 20. jQuery:我可以做$('。superset')。$('。within')而不是$('。within',$('。superset'))?
- 21. Array-within-array项目替换
- 22. if function within function breaks javascript
- 23. Java Collection-Within-Collection并发性
- 24. array.array.tostring()的Python 2.5版本?
- 25. Python 2.5导入dll AttributeError
- 26. Windows Python 2.5 Traceback.py Nonetype错误
- 27. Python 2.5 time.time()十进制
- 28. 塔 - 使用Python 2.5或2.6?
- 29. 在Python 2.5上使用MySQLdb
- 30. 的Python 2.6至2.5小抄
更换应该是不'最后:如果name:name.close()' ? –
不,名称的分配应该在try块之外进行。 –