是否有將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塊之外進行。 –