Disabling python's assert() without -0 flag

前端 未结 3 2223
悲哀的现实
悲哀的现实 2020-12-15 09:26

I\'m running a python script from inside a different software (it provides a python interface to manipulate its data structures).

I\'m optimizing my code for speed

3条回答
  •  渐次进展
    2020-12-15 09:52

    You may be able to do this with an environment variable, as described in this other answer. Setting PYTHONOPTIMIZE=1 is equivalent to starting Python with the -O option. As an example, this works in Blender 2.78, which embeds Python 3.5:

    blender --python-expr 'assert False; print("foo")'
    
    PYTHONOPTIMIZE=1 blender --python-expr 'assert False; print("foo")'
    

    The first command prints a traceback, while the second just prints "foo".

提交回复
热议问题