jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.14k stars 948 forks source link

Simple representation, str method for Layout #3906

Open marscher opened 5 months ago

marscher commented 5 months ago

Problem

In order to easily inspect the a Layout instance of a widget, it'd be very useful to have a representation which displays all attributes. This way one can better understand the current layout.

Proposed Solution

A simple method which collects all attributes and formats them to a string:

def __str__(self):
    attributes = []
    for key, value in self.__dict__.items():
        if not key.startswith('_'):
            attributes.append(f"{key}={value}")
    return f"Layout({', '.join(attributes)})"