[py2exe] __debug__ = 0 - how?

F

F. GEIGER

I'd like to get rid of all __debug__ code fragments in my app. So I have
changed the invocation of python to python -O in Windows Explorer. I use
a wx.TextCtrl to display th e__debug__ flag:

if __debug__:
text = "__debug__ = 1"
else:
text = "__debug__ = 0"

etc.

The control shows "__debug__ = 0" as expected.

When I build an exe file, __debug__ still seems to be on. Does py2exe
switch -O off again or doesn't the -O get thru to py2exe? If so, does
there exist a py2exe-option to switch on optimizing for exe files?

Kind regards
Franz GEIGER
 
T

Thomas Heller

F. GEIGER said:
I'd like to get rid of all __debug__ code fragments in my app. So I
have changed the invocation of python to python -O in Windows
Explorer. I use a wx.TextCtrl to display th e__debug__ flag:

if __debug__:
text = "__debug__ = 1"
else:
text = "__debug__ = 0"

etc.

The control shows "__debug__ = 0" as expected.

When I build an exe file, __debug__ still seems to be on. Does py2exe
switch -O off again or doesn't the -O get thru to py2exe? If so, does
there exist a py2exe-option to switch on optimizing for exe files?

You have to specify it for py2exe, it doesn't use the __debug__ from Python:

C:\sf\py2exe\py2exe\samples\simple>setup py2exe -h
Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message

Options for 'py2exe' command:
--optimize (-O) optimization level: -O1 for "python -O", -O2 for "python
-OO", and -O0 to disable [default: -O0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--dist-dir (-d) directory to put final built distributions in (default is
dist)
--excludes (-e) comma-separated list of modules to exclude
--ignores comma-separated list of modules to ignore if they are not
found
--includes (-i) comma-separated list of modules to include
--packages (-p) comma-separated list of packages to include
--compressed (-c) create a compressed zipfile
--why why is module <m> included

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

Thomas
 
F

F. GEIGER

Thomas said:
I'd like to get rid of all __debug__ code fragments in my app. So I
have changed the invocation of python to python -O in Windows
Explorer. I use a wx.TextCtrl to display th e__debug__ flag:

if __debug__:
text = "__debug__ = 1"
else:
text = "__debug__ = 0"

etc.

The control shows "__debug__ = 0" as expected.

When I build an exe file, __debug__ still seems to be on. Does py2exe
switch -O off again or doesn't the -O get thru to py2exe? If so, does
there exist a py2exe-option to switch on optimizing for exe files?


You have to specify it for py2exe, it doesn't use the __debug__ from Python:

C:\sf\py2exe\py2exe\samples\simple>setup py2exe -h
Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message

Options for 'py2exe' command:
--optimize (-O) optimization level: -O1 for "python -O", -O2 for "python
-OO", and -O0 to disable [default: -O0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--dist-dir (-d) directory to put final built distributions in (default is
dist)
--excludes (-e) comma-separated list of modules to exclude
--ignores comma-separated list of modules to ignore if they are not
found
--includes (-i) comma-separated list of modules to include
--packages (-p) comma-separated list of packages to include
--compressed (-c) create a compressed zipfile
--why why is module <m> included

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

Thomas

Ouch, a plain RTFM, embarrassing...

Works now as expected. Thanks a lot, Thomas!

Kind regards
Franz GEIGER
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top