Screen Too Small

This course material requires a larger screen to properly display the terminal and editor interfaces.

Please use a tablet, laptop, or desktop computer for the best learning experience.

You can continue browsing, but the experience will be significantly limited.

From Debug to Deploy: Upgrade Logging Statements

Refactor messy print debug statements into structured logger calls using Pythonโ€™s logging module. Macros will save you from repetition.

Starting Text

vim@sandbox: ~/start.txt
vim
import logging logger = logging.getLogger(__name__) def fetch_data(url): print("start") response = requests.get(url) return response.json() def process_data(data): print("debug") cleaned = clean(data) return cleaned def save_results(results): print("yo") with open('out.json', 'w') as f: json.dump(results, f)

Expected Output

vim@sandbox: ~/expected.txt
vim
import logging logger = logging.getLogger(__name__) def fetch_data(url): logger.info("Entering fetch_data") response = requests.get(url) return response.json() def process_data(data): logger.info("Entering process_data") cleaned = clean(data) return cleaned def save_results(results): logger.info("Entering save_results") with open('out.json', 'w') as f: json.dump(results, f)

Hold on, cowboy

You gotta sign up to view challenges

New challenges appear every week. They're fun, and insightful

Sign up or sign in now!