How to debug python programs?

as detailed in the title: for example, how to view some property values and method values of an object generated in python code? How do I print it?

Mar.06,2021

the general debugging methods are:
1. Use the print function.
2. Use breakpoints such as pdb,ipdb to debug.
3. Use IDE to debug, such as setting breakpoints with pycharm where you need to debug, and then right-click to select Evaluate expression.


dir ([object]) returns a list of all valid attributes of object

or

>>> class new_class():
...   def __init__(self, number):
...     self.multi = int(number) * 2
...     self.str = str(number)
... 
>>> a = new_class(2)
>>> a.__dict__
{'multi': 4, 'str': '2'}
>>> a.__dict__.keys()
dict_keys(['multi', 'str'])

if you are developing in IDE (such as PyCharm), you can use your own debug

if it is a terminal, you can use pdb


When the

dir () function takes no arguments, it returns a list of variables, methods, and defined types in the current scope; when with parameters, it returns a list of properties and methods of parameters.

print(dir(page_data))
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4313e-434e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4313e-434e2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?