lecture 20 debugging

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

raising exceptions

stop running the code in this function and move the program execution to the except statement (try & except)

-raise keyword

-call to Exception() function

-a string w/ error message passed to Exception() function

2
New cards

getting the traceback as a string

error message, line # that caused error, sequence of function calls that led to error

3
New cards

what are assertions?

sanity check to make sure code isn’t doing something obviously wrong

“I assert that the condition holds true, and if not, there is a bug somewhere, so immediately stop the program”

4
New cards

assert format

assert ages[0] <= ages[-1]

5
New cards

logging

makes it easy to create a record of custom messages that you write

-messages describe when program execution has reached the logging function call & list any variable you have specified at that point in time

6
New cards

logging module format

import logging

logging.basicConfig(level=logging.DEBUG, format= ‘$(asctime)s - %(levelname)s - %(message)s’)

7
New cards

basicConfig() function

what you want to see, how you want those details displayed

8
New cards

logging.debug()

calls printed out not just string passed to them

-timestamp

DEBUG

9
New cards

don’t debug w/ what function?

print()

10
New cards

logging levels (lowest to highest)

DEBUG, INFO, WARNING, ERROR, CRITICAL

11
New cards

logging.debug()

used for small details; only care about these messages only when diagnosing problems

12
New cards

logging.info()

used to record info on general events in program or confirm that things are working at their point in program

13
New cards

logging.warning()

used to indicate a potential problem that doesn’t prevent the program from working but might do so in the future

14
New cards

logging.error()

used to record an error that caused the program to fail to do something

15
New cards

logging.critical()

used to indicate fatal error that has caused or is about to cause the program to stop running entirely

16
New cards