Member-only story
Simple alternative ways to debug Python/Django without a debugger
It is a very common habit for developers to print out values in the console when attempting to debug during programming. I normally use the vscode debugger for python and it has a lot of useful features. I also use Django Debug toolbar but sometimes I’m in the console or can’t be bothered running different commands or setting up a debugger, so what do I do?
I’ll share three other functions that can be used to debug your python code.
1. __dict__
the __dict__
object is a very useful attribute of python objects. The python documentation website explains the function as follows
A dictionary or other mapping object used to store an object’s (writable) attributes
This allows you to see the readable attribute name as well as the values it contains. You use it by calling .__dict__
on the object e.g. user.__dict__
as shown in the screenshot below.
2. dir
The dir function allows you to return all properties and methods of an object including the built in ones as a list. This is very useful especially when you are…