[SciPy-user] fsolve help

David M. Cooke cookedm at physics.mcmaster.ca
Sat Jul 15 01:42:28 EDT 2006


On Fri, Jul 14, 2006 at 08:51:19PM -0700, David Grant wrote:
> On 7/14/06, Christian Kristukat <ckkart at hoc.net> wrote:
> >
> > Or even easier, put a
> >
> > from __future__ import division
> >
> > at the beginning of your script. Then division default to floating point operations.
> 
> What exactly does that do? What is __future__ all about?

It's the Python developers' way of saying "sometime in the future, this
option will be the default. But for now, you can be future-proof.."
See PEP 236 (http://www.python.org/dev/peps/pep-0236/) for __future__,
and PEP 238 (http://www.python.org/dev/peps/pep-0238/) for division.

In this case, this statement at the top of your module means that within
that module, the '/' does "true" division, e.g., 1/2 == 0.5. To get
integer division (the previous behaviour), do 1//2 == 0.

"true" division will be the default in Python 3.0; you don't have to
worry about the 2.x series (although, for numerical computation, it's
*much* more convienent).

Previous uses of 'from __future__ import <blah>' have included
'nested_scopes', which you can still find in odd corners of scipy,
and 'generators'.

There's also the fun 'from __future__ import braces' to try to use { }
for blocks instead of indentation. (Try it in the interpreter.)

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca



More information about the SciPy-User mailing list