From: sharpblade <sha...@gm...> - 2010-03-31 15:41:30
|
I am writing a rather large application, which will be compiled using py2exe. One issue I have come into is that for testing purposes my code has a lot of print statements in it, which I don't want inside the main "final" application. To fix this I simply routed all sys.stdout into a black hole, and it works fine. However this got me thinking about a feature that could be added into py2exe - some kind of global compile-time variables that can be queried at runtime. For example to switch between my debug and "final" builds I flick a boolean object from True to False, then run my setup.py. Is it possible to give py2exe a dictionary of keys and values that gets hardcoded into the completed binary (Maybe in the bootstrap somewhere, or in a extra module that gets included automatically), so I can have one codebase and simply change the setup.py values. Example: ---------------------------------------------- import py2exevars if not py2exevars.get("debug"): sys.stdout = blackHole() ---------------------------------------------- The value of "debug" is set in the setup.py file, so you can alter code flow by changing the setup.py rather than the actual code itself. |
From: Fahlgren, E. <efa...@li...> - 2010-03-31 16:19:23
|
Just hack boot_common.py to do what you want in the .exe version. From: sharpblade [mailto:sha...@gm...] Sent: Wednesday, March 31, 2010 8:41 AM To: py2...@li... Subject: [Py2exe-users] Py2exe "preprocessor" suggestion I am writing a rather large application, which will be compiled using py2exe. One issue I have come into is that for testing purposes my code has a lot of print statements in it, which I don't want inside the main "final" application. To fix this I simply routed all sys.stdout into a black hole, and it works fine. However this got me thinking about a feature that could be added into py2exe - some kind of global compile-time variables that can be queried at runtime. For example to switch between my debug and "final" builds I flick a boolean object from True to False, then run my setup.py. Is it possible to give py2exe a dictionary of keys and values that gets hardcoded into the completed binary (Maybe in the bootstrap somewhere, or in a extra module that gets included automatically), so I can have one codebase and simply change the setup.py values. Example: ---------------------------------------------- import py2exevars if not py2exevars.get("debug"): sys.stdout = blackHole() ---------------------------------------------- The value of "debug" is set in the setup.py file, so you can alter code flow by changing the setup.py rather than the actual code itself. |
From: Aahz <aa...@py...> - 2010-03-31 16:31:19
|
On Wed, Mar 31, 2010, sharpblade wrote: > > I am writing a rather large application, which will be compiled using > py2exe. One issue I have come into is that for testing purposes my > code has a lot of print statements in it, which I don't want inside > the main "final" application. This isn't answering your question, but the correct way to do this is to use the logging module. -- Aahz (aa...@py...) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? |