views:

70

answers:

1

I'm working on a fairly simple Pylons 0.9.7 application. How do I tell, in code, whether or not debugging is enabled? That is, I'm interested in the value of the debug setting under [app:main] in my INI file. More generally, how do I access the other values from there in my code?

+3  A: 
# tmp.py
print __debug__


$ python tmp.py
True
$ python -O tmp.py
False

I'm not sure if this holds in Pylons, as I've never used that -- but in "normal" command line Python, debug is enabled if optimizations are not enabled. The -O flag indicates to Python to turn on optimizations.

Actually, there's this snippet from Pylons documentation:

    # Display error documents for 401, 403, 404 status codes (and
    # 500 when debug is disabled)
    if asbool(config['debug']):
        app = StatusCodeRedirect(app)
    else:
        app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

Looks like config['debug'] is what you want.

Mark Rushakoff
Thanks, config['debug'] has the value I want. I did look in the Pylons documentation, but looks like I missed it.
Evgeny