tags:

views:

22

answers:

1

I'm just getting started with pylons, and am trying to figure out how to view the contents of variables for debugging without rendering the template.

For example:

class IndexController(BaseController):

def index(self):
    # Return a rendered template
    #return render('/index.mako')
    # or, return a response
    return render('/index.mako' )

def test(self):
    v = request.params
    return v

I would like to view the contents of array v, but I can't figure out how to do it !!

Thanks.

+1  A: 

You can use cgitb to debug web applications, it can output detailed tracebacks to files, including variables contents. Here is an article detailing how to use it.

If you can see the server stdout you can also simply print the variable, or else write it to a file: open("my-debug-log.txt", "w").write(repr(variable)). pprint can help making complex data structures (nested arrays, complex dicts, etc...) easier to read in this case.

Luper Rouch
Thanks! However I'm just looking for something really simple to display the contents of a variable without rendering it in mako.
ensnare
You can simply write the repr of the variable you want to see in a file then, or print it if you see the server's console.
Luper Rouch
That worked. Thank you.
ensnare