Assertion for python scripts
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Nov 2 20:32:34 EDT 2007
En Fri, 02 Nov 2007 16:53:12 -0300, matthias
<matthiasblankenhaus at yahoo.com> escribió:
> On Nov 2, 12:12 pm, "Matt McCredie" <mccre... at gmail.com> wrote:
>> On 11/2/07, matthias <matthiasblankenh... at yahoo.com> wrote:
>>
>> > I know that "-O" turns off assertions in general. However, how do I
>> > pass thus parameter to
>> > python to an executable script ?
>> Use:
>> python -O -mcompileall path
>>
> This indeed creates a file with the name assert.pyo. That must be the
> optimized one.
>
> Now I try this:
>
> # ./assert.py
> Traceback (most recent call last):
> File "./assert.py", line 3, in ?
> assert 1 > 1, "ASSERTTION !"
> AssertionError: ASSERTTION !
>
> Ok, so it still uses the unoptimized version.
>
> Now I try this:
>
> # chmod 755 assert.pyo
> # ./assert.pyo
> bash: ./assert.pyo: cannot execute binary file
>
> Here is my problem: I want to have an optimized executable version of
> assert.py.
Move all your code into modules; those modules can be pre-compiled with -O
as above.
Your main script should contain just a few lines; import the other modules
from inside your main script.
When you import "foo", if python finds "foo.pyo" and it's up to date, it
will use it instead of foo.py;
foo.py doesn't have to be available either.
--
Gabriel Genellina
More information about the Python-list
mailing list