Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16682
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Fwd: class print method... |
| Date | 2011-12-05 14:55 -0500 |
| References | (1 earlier) <4EDC775D.4000906@davea.name> <CALKjt2dTF=k-2pQy7YQPsEWexWGK5ej5w721Es+BtQnnoHghDg@mail.gmail.com> <CALKjt2caxDh_GBwtBaNDzF6=Q=tPpyNe4db1BeUX16zda-XvhQ@mail.gmail.com> <jbie5n$b6c$1@dough.gmane.org> <4EDCC29D.7010903@davea.name> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3317.1323114924.27778.python-list@python.org> (permalink) |
On 12/5/2011 8:09 AM, Dave Angel wrote:
> useful, such as if you print a list. The __str__() method of list calls
> the __repr__() for each object inside it. So it can be useful to define
> both, even if you decide to have them do the same thing.
If you want __str__ and __repr__ to do the same thing, you only need
*one* def statement and an assignment.
def __str__(self): <whatever>
__repr__ = __str__
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Fwd: class print method... Terry Reedy <tjreedy@udel.edu> - 2011-12-05 14:55 -0500
csiph-web