from __future__ import ... within an RExec?

greg greg at cosc.canterbury.ac.nz
Sun Aug 18 07:05:23 EDT 2002


Erik Max Francis wrote:
> 
> Yes, there are other solutions with varying levels of hackery involved.
> I'm wondering why a standard feature (from __future__ import division)
> doesn't work in a RExec.

Essentially because (unusually for Python) it's a compile-time
feature, not a run-time feature. When a module is being compiled
to bytecode, the parser recognises "from __future__ import"
statements and generates different bytecode as a result.

There's probably some flag you can set somewhere somehow so that
the strings you pass to RExec get compiled in a true-division
environment, but I don't know the details.

Another way would be to use a late enough version of Python
that true division is no longer in the future (although
I'm not sure whether such a version has been released
yet).

Greg



More information about the Python-list mailing list