recommended __future__ imports for 2.5?

Terry Reedy tjreedy at udel.edu
Mon Nov 24 15:50:51 EST 2008


Joe Strout wrote:
> OK, this will probably be placed into the "stupid question" category by 
> some, but I really am in need of a bit of guidance here.
> 
> I just rediscovered the "gotcha" of integer division in 2.5 and below, 
> and found (to my delight) that this is fixed in 3.0, and fixable in 
> older versions of Python with "from __future__ import division".  Once I 
> stumbled across that, I was able to find the relevant PEP (#238) and 
> read more about it.  So now that import has become part of our standard 
> boilerplate at the top of each file, along with the path to Python and 
> the UTF-8 encoding declaration.
> 
> Now I'm wondering what other boilerplate I should be using.  I'm not yet 
> ready to upgrade to Python 2.6 -- parts of our business model rely on 
> using the standard Python installed with Mac OS X (which is currently 
> 2.5.1).  But I would like our code to be as future-proof as possible, 
> especially in cases like this where we're talking about changes to 
> existing behavior, rather than the introduction of entirely new features 
> (like the "with" statement).
> 
> I found <http://www.python.org/doc/2.5.2/ref/future.html>, which lists 
> the available future imports, but doesn't link to any documentation on 
> them.  Searching for each one on google turns up some probably-relevant 
> PEPs, but it's hard for a relative newbie to tell for sure exactly what 
> was implemented when and which is merely a summary of discussion.
> 
> So... besides "division", are there any other imports you would 
> recommend as standard for any new code written in 2.5?  And what else do 
> you experienced gurus put at the top of every Python file?

2.5 (and 2.3 and 2.2) already has 'generators' and 'nested_scopes', so 
forget those unless programming for 2.2-.
"with_statement" is needed if and only if you use a with statement.
"absolute_import" ? I don't know what difference that makes. The doc on 
the import statement might say.

tjr




More information about the Python-list mailing list