Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63755 > unrolled thread
| Started by | Daniel da Silva <var.mail.daniel@gmail.com> |
|---|---|
| First post | 2014-01-11 23:56 -0500 |
| Last post | 2014-01-11 23:56 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python 3 __bytes__ method Daniel da Silva <var.mail.daniel@gmail.com> - 2014-01-11 23:56 -0500
| From | Daniel da Silva <var.mail.daniel@gmail.com> |
|---|---|
| Date | 2014-01-11 23:56 -0500 |
| Subject | Re: Python 3 __bytes__ method |
| Message-ID | <mailman.5359.1389508769.18130.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Sat, Jan 11, 2014 at 9:44 PM, Ethan Furman <ethan@stoneleaf.us> wrote:
> On 01/11/2014 06:19 PM, Daniel da Silva wrote:
>
>>
>> One use case is:
>> Suppose you have existing function that accepts a /bytes/ object. If you
>> subclass /bytes/ and want it to be guaranteed
>> to work with that function, you can override/__bytes__()/ to use the
>> logistics of your subclass implementation.
>>
>
> I don't think so, for two reasons:
>
> 1) bytes objects do not have a __bytes__ method,
>
> 2) if the function is expecting a bytes object, it is unlikely to call
> bytes() on it.
In general __typename__() methods are for explicit typename(obj)
conversion. There is __int__(), __str__(), etc. They are what is behind
int('3') == 3 and str(4) == '4'. If for no other reason, __bytes__() is
there for symmetry. I agree with you that realistic use cases are hard to
think of.
Does that answer your question better?
All the best,
Daniel
Back to top | Article view | comp.lang.python
csiph-web