From BlenderWiki
Python Tips
I'm collecting useful script snippets here, that might also help others.
Debugging
Interactive console
For interactive debugging in the middle of some python code just insert this line as "breakpoint":
__import__("code").interact(local=locals())
Blender Game Engine
Find out the objects that have logic bricks that use a specific text block
Sounds difficult, but can be useful sometimes.
for text in bpy.data.texts: print(text.name, text.users_logic)