Vim Dojo challenge
Refactor messy print debug statements into structured logger calls using Python’s logging module. Macros will save you from repetition.
Start
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)
Goal
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)
Members only
You gotta sign in to take on challenges. New ones drop every week — they're fun, and insightful.