Latest Version: 0.9.6.2
  Dashboard > Pylons Cookbook > ... > Guides to Pylons for people in a hurry > Pylons debugger for people in a hurry
  Pylons Cookbook Log In | Sign Up   View a printable version of the current page.  
  Pylons debugger for people in a hurry
Added by Brendan Arnold, last edited by Brendan Arnold on Aug 23, 2007  (view change) show comment
Labels: 

Pylons debugger for people in a hurry

This is one of a set of quick guides for getting started with the different components of Pylons.

Introduction

When we have an error in our Pylons code we get the Error Traceback on a Pylons page.

if the problem is not immediately obvious from the debugging text and inspection of the code then you may want to try the following.

Setting a breakpoint

If the code is your own, just before the line of code that caused the error add the following line,

raise RuntimeError()

This stops the program just before the error and allows us to inspect the state (variable values etc.) using the interactive Python shell built into the webpage.

Click on the cross on the traceback to reveal a text box. You can now enter Python code to find out the program state, for instance,

>>> dir(mr_jones)
 ['name', 'address' etc.. ]
>>> dir(mr_jones.name)
 None

If our code had been expecting mr_jones.name to be assigned to something other than None then this would have raised an error. dir is also useful for determining what names are in the current namespace,

>>> dir()
 ['__builtins__', '__doc__' etc.. ]

type(), which returns an object's type, is also useful for determining errors in code.

Further reading

  • IBM developer works has an article on Python introspection detailing more python builtins you can use to diagnose problems

Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators
Top