Guance Learn

Observability questions

Focused answers for definitions, architecture choices, troubleshooting, pricing, and evaluation.

Log an exception with its traceback in Python illustration
Explainer

Log an exception with its traceback in Python

Use logger.exception or exc_info to preserve exception tracebacks, and configure a hook for uncaught main-thread exceptions.

Read environment variables in Python illustration
Explainer

Read environment variables in Python

Read required and optional environment variables, convert configuration values, and load a .env file during local development.

Get the index and value in a Python for loop illustration
Explainer

Get the index and value in a Python for loop

Use enumerate to iterate with a counter, set the starting number, and combine it with zip or dictionary items.

Illustration of Git branches and version history
Technical guide

Add an empty directory to a Git repository

Keep a directory in a Git checkout with a placeholder file, or create it during setup. Use ignore rules that allow the placeholder to remain tracked.

Add keys to a Python dictionary illustration
Explainer

Add keys to a Python dictionary

Insert or replace dictionary entries with assignment, merge values with update, and set a default only when a key is missing.

Append text to a file in Python illustration
Explainer

Append text to a file in Python

Open a file in append mode, write complete lines, read appended content, and distinguish flushing buffers from syncing data to disk.

Assert approximate equality with pytest illustration
Explainer

Assert approximate equality with pytest

Compare floating-point results with pytest.approx, choose meaningful tolerances, and handle sequences, dictionaries, NumPy arrays, and NaN.

Assert that Python code raises an exception with pytest illustration
Explainer

Assert that Python code raises an exception with pytest

Use pytest.raises to check exception types, match error messages, inspect exception details, and avoid assertions that never run.

Reorder columns in a pandas DataFrame illustration
Explainer

Reorder columns in a pandas DataFrame

Select columns in a new order, move a single column with pop and insert, and understand how selection differs from reindex.

Customize timestamps in Python logging illustration
Explainer

Customize timestamps in Python logging

Set logging datefmt, include milliseconds, choose local time or UTC, and supply formatter settings through dictConfig.

Check whether a Python list is empty illustration
Explainer

Check whether a Python list is empty

Use a list’s truth value to test for emptiness, distinguish an empty list from None, and handle NumPy arrays separately.

Python programming and application logging
Explainer

Check whether an object has an attribute in Python

Use hasattr and getattr to check Python attributes, retrieve defaults, and handle properties or dynamic lookup without hiding unexpected errors.