On Thu, Jul 16, 2009 at 8:22 AM, Earl Lapus <earl.la...@gmail.com> wrote:
> hi all, > > This is a silly newbie question, so please bear with me :D > > Example: > ... > def DoSomethingAwful(request): > if __debug__: > DoDebugStuff() > ProcessRequest() > ... > > In the example above, I want django to call DoDebugStuff() *ONLY* if I'm > running my app on my development environment. So, my question is: Is the > __debug__ Python flag implicitly toggled depending on the value of the DEBUG > setting found in settings.py? http://docs.python.org/reference/simple_stmts.html under the discussion of assert says this about __debug__: These equivalences assume that __debug__ and AssertionError refer to the built-in variables with those names. In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time. Note that it is unnecessary to include the source code for the expression that failed in the error message; it will be displayed as part of the stack trace. Assignments to __debug__ are illegal. The value for the built-in variable is determined when the interpreter starts. So it doesn't sound to me like there is any way Django could (or should) attempt to make this value in any way dependent on settings DEBUG value. > I'm asking this because I want part of my code to be executed only during > development and not in production. So, I was thinking of wrapping them > inside __debug__. (Basically, I was thinking of something like C macros > where you can toggle debugging) > > If there is/are other ways to do this please let me know... I'd be happy to > try them out. > Make the code dependent on checking settings.DEBUG directly? Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---