好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

from __future__ import with_statement

from __future__ import with_statement

http://docs.python.org/library/__future__

http://stackoverflow.com/questions/3791903/which-python-version-need-from-future-import-with-statement/3792223#3792223

up vote 0 down vote favorite

Currently i'm using python 2.6.5, I didn't use from __ future __ import with_statement,it can use with statement all right. I want to know in which version we need use from __ future __ import with_statement,which not?

link | edit | delete | flag

asked  2 hours ago

mlzboy
21 4

add comment

3 Answers

oldest newest votes

up vote 2 down vote accept

You only need it in Python 2.5. Older versions (<= 2.4) don't support it and newer versions (>= 2.6) have it enabled by default.

So if you want to support Python >= 2.5, you can simply put the  from __future__ import with_statement  at the beginning. For newer versions, it will simply be ignored.

link | flag

answered  2 hours ago

AndiDog
9,886 1 4 20

enter at least 15 characters

up vote 0 down vote accept

From the doc:

  New     in   version   2.5  .  

link | flag

answered  2 hours ago

Lie Ryan
2,121 11

enter at least 15 characters

up vote 1 down vote accept

__future__  features are self-documenting. Try this:

  >>>     from   __future__   import   with_statement
>>> with_statement . getOptionalRelease ()
( 2 , 5 , 0 , 'alpha' , 1 )
>>> with_statement . getMandatoryRelease ()
( 2 , 6 , 0 , 'alpha' , 0 )

These respectively indicate the first release supporting  from __future__ import with_statement and the first release to support it without using  from __future__ .

Also, read this:

  >>>     import   __future__
>>> help ( __future__ )

link | flag

answered  11 mins ago

查看更多关于from __future__ import with_statement的详细内容...

  阅读:38次