On Thu, Oct 7, 2010 at 1:50 AM, Ryan <[email protected]> wrote:
> Hi,
>
> How do I tell Maya to run python with optimization requested (command
> line option -O). I have a number of asserts in my libs and would like
> them removed when the source is compiled to byte code.
>
> Thanks,
> Ryan

You can also set the PYTHONOPTIMIZE environment variable.

       PYTHONOPTIMIZE
              If  this is set to a non-empty string it is equivalent to speci‐
              fying the -O option. If set to an integer, it is  equivalent  to
              specifying -O multiple times.

There are a number of drawbacks to using the .pyo files.  I'd would
not recommend it.

Question -- what's the point of having the asserts in the first place
if you're going to throw them out?  It also makes it harder to debug.
IIRC you won't get tracebacks either.

The standard Python approach is to write unit tests and test the
assertions there.


>From the python wiki:

http://wiki.python.org/moin/UsingAssertionsEffectively

Assertions are not a substitute for unit tests or system tests, but
rather a complement. Because assertions are a clean way to examine the
internal state of an object or function, they provide "for free" a
clear-box assistance to a black-box test that examines the external
behaviour.

Assertions should *not* be used to test for failure cases that can
occur because of bad user input or operating system/environment
failures, such as a file not being found. Instead, you should raise an
exception, or print an error message, or whatever is appropriate. One
important reason why assertions should only be used for self-tests of
the program is that assertions can be disabled at compile time.

If Python is started with the -O option, then assertions will be
stripped out and not evaluated. So if code uses assertions heavily,
but is performance-critical, then there is a system for turning them
off in release builds. (But don't do this unless it's really
necessary. It's been scientifically proven that some bugs only show up
when a customer uses the machine and we want assertions to help there
too. :)

-- 
    David

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to