On Wed, Jan 22, 2020 at 6:43 AM Eric V. Smith <e...@trueblade.com> wrote:
>
> On 1/21/2020 2:25 PM, Chris Angelico wrote:
> >
> > Hmm. Maybe this should be a recipe in the docs, or something: "how to
> > make a repr that reconstructs an object".
> >
> > def describe(obj, attrs):
> >      attrs = [f"{a}={getattr(obj, a)!r}" for a in attrs]
> >      return f"{type(obj).__name__}({", ".join(attrs)})"
> >
> > def __repr__(self):
> >      return describe(self, "name age spam ham location".split())
> >
> > This comes up often enough that I think it'd be a useful thing to
> > point people to.
>
> reprlib would seem to be the place for this, if it's not already there.
>

And... I did not know about that module. Cool! That would be superior
to a docs recipe. I'll spin this off as a new thread.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WP74PEDSNWIA6VCAKR3LHJRDU3GWUHZJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to