使用python 2.6.5,我可以在不调用from __future__ import with_statement
的情况下使用with
语句。我怎么知道哪个版本的Python支持with
而没有从__future__
专门导入?__future__ import with_statement需要哪个python版本?
24
A
回答
45
__future__
特点是自我记录。试试这个:
>>> from __future__ import with_statement
>>> with_statement.getOptionalRelease()
(2, 5, 0, 'alpha', 1)
>>> with_statement.getMandatoryRelease()
(2, 6, 0, 'alpha', 0)
它们分别表示第一个版本支持from __future__ import with_statement
和第一个版本来支持它,而无需使用from __future__
。
而且,阅读本:
>>> import __future__
>>> help(__future__)
16
你只需要Python 2.5。旧版本(< = 2.4)不支持它,而较新版本(> = 2.6)默认启用它。
所以如果你想支持Python> = 2.5,你可以简单地把from __future__ import with_statement
放在开头。对于较新的版本,它将被忽略。
1
从DOC:
New in version 2.5.
相关问题
- 1. 需要从__future__
- 2. Python如何处理“from __future__ import division”?
- 3. javapns 2.1需要哪个JDK版本?
- 4. UIContainerView需要哪个版本的iOS?
- 5. 我需要哪个版本的Flex Builder?
- 6. ios7.1 beta - 我需要哪个版本?
- 7. 我需要哪个版本的Flash Builder?
- 8. str_split需要哪个PHP版本?
- 9. Struts 1.3.10需要哪个版本的java
- 10. 现在需要哪个版本?
- 11. 哪个SDK版本变量需要REQUEST_INSTALL_PACKAGES?
- 12. 我需要哪个版本的Windows SDK?
- 13. 要学哪个python版本? (noob问题)
- 14. 哪个版本的rails需要更低版本的RubyGems?
- 15. python 2.7.6需要哪个pygame?
- 16. 我需要安装哪些sdk版本?
- 17. CloudFoundry需要哪种版本的Ruby?
- 18. 为什么不能从Python中的__future__ import formatted_string_literals <3.6?
- 19. 语音到文本应用需要哪个最低版本的Android版本
- 20. 如何告诉python要使用哪个版本的libmysqlclient.so?
- 21. .NET版本需要
- 22. 需要Android版本
- 23. 我需要上传到Play商店的哪个版本的APK?
- 24. jQueryMobile:我的应用程序需要使用哪个版本
- 25. 哪个版本的Hibernate是独立的(不需要JPA实现)?
- 26. C#哪个.net版本不需要我的应用程序
- 27. 需要哪个gcc版本才能使用C++ 11中的unordered_map?
- 28. 如何判断在CMakeLists.txt中需要哪个最小CMake版本?
- 29. 当需要宝石时安装哪个版本的宝石
- 30. JW Player:我需要展示广告的哪个版本?