New PEP: The directive statement

Bruce Sass bsass at freenet.edmonton.ab.ca
Fri Mar 23 17:08:18 EST 2001


On 23 Mar 2001, Martin von Loewis wrote:
> Bruce Sass <bsass at freenet.edmonton.ab.ca> writes:
>
> > For example, I'd rather do...
> >
> > use:
> >     new_math.//
> >     result = new_math_based_function()
> > except NewMathError:
> >     result = old_math_based_function()
> >
> > ...and have the compiler use the appropriate source depending on what
> > the interpreter can handle, rather than do a check of the
> > "sys.version"[1] or try to catch a run-time exception.
>
> And you would supply both new_math_based_function and
> old_math_based_function in the same module, outside of the use: block?
> That is probably difficult to implement, as the compiler *when
> processing new_math_based_function* needs to know what / means.

I'd have figured too costly (timewise), rather than too difficult...
but since it is a compile-time operation (done once, or infrequently,
for most users), maybe the hit would be worth the expense.

In general, have the compiler scan the source to find out what the
program is trying to use, then compile according to that information.
With this specific example, presumably there will be broken, unused,
old_math_based_function-(s) kicking around in the .pyc (removing them
for the .pyo would probably be difficult).

However, it may be necessary to have two pieces in place,  e.g.,

#!/usr/bin/env python
use:
    new_feature
.
.
.
use:
    new_feature
    # new code
except:
    # old code

...but that would really depend on new_feature and the programmer,
with some it may only make sense to do...

#!/usr/bin/env python
use:
    new_feature
except:
    print "Sorry, you need new_feature to run this program!"
    sys.exit(1)

...and if always having declarative use: blocks at the top of the file
would help with compiling, then it should be required.


- Bruce






More information about the Python-list mailing list