4. Basic Debugging

4.1. Run in the console

  • Execute cell
  • Run File in the console

4.2. print

DATA = ['a', 'b', 'c', [1, 2, 3]]

for element in DATA:
    print(element)
    # a
    # b
    # c
    # [1, 2, 3]

4.2.1. Case Study

4.2.1.1. Good

settings.py:
ADMIINSTRATORS = '[email protected]',
main.py:
from settings import ADMIINSTRATORS

for config in MY_CONFIGURATION:
    print(config)

# [email protected]

4.2.1.2. Bad

settings.py:
ADMIINSTRATORS = '[email protected]'
main.py:
from settings import ADMIINSTRATORS

for config in MY_CONFIGURATION:
    print(config)

# j
# o
# s
# e
# .
# j
# ...
# g
# o
# v

4.3. pprint

from pprint import pprint

pprint(...)
import json
from pprint import pprint

DANE = '{"contacts": [{"id": 1, "created": "2018-06-13T09:57:55.405Z", "modified": "2018-06-13T10:16:13.975Z", "reporter_id": 1, "is_deleted": false, "first_name": "José", "last_name": "Jiménez", "date_of_birth": "1969-07-24", "email": "[email protected]", "bio": "", "image": "33950257662_d7561fb140_o.jpg", "status": null, "gender": null}, {"id": 2, "created": "2018-06-13T10:26:46.948Z", "modified": "2018-06-13T10:26:46.948Z", "reporter_id": 1, "is_deleted": false, "first_name": "Matt", "last_name": "Kowalski", "date_of_birth": null, "email": null, "bio": "", "image": "", "status": null, "gender": null}, {"id": 3, "created": "2018-06-13T10:26:55.820Z", "modified": "2018-06-13T10:26:55.820Z", "reporter_id": 1, "is_deleted": false, "first_name": "Иван", "last_name": "Иванович", "date_of_birth": null, "email": null, "bio": "", "image": "", "status": null, "gender": null}, {"id": 15, "created": "2018-06-13T14:34:42.353Z", "modified": "2018-06-13T14:34:43.638Z", "reporter_id": null, "is_deleted": false, "first_name": "Mark", "last_name": "Watney", "date_of_birth": null, "email": null, "bio": null, "image": "", "status": null, "gender": null}]}'

dane = json.loads(DANE)
pprint(dane)
pprint(globals())
from pprint import pprint

print(globals())
pprint(globals())

def hello(a, b, text='My name...'):
    first_name = 'José'
    last_name = 'Jiménez'
    pprint(locals())
    return locals()


hello(1, 2)

4.4. locals()

def hello(a, b, text='My name...'):
    first_name = 'José'
    last_name = 'Jiménez'
    my_vars = locals()
    del my_vars['text']
    return my_vars

4.5. Using debugger in IDE

4.5.1. Setting Break Points

4.5.2. Inspecting variable values

4.5.3. Resume Program