[Python-ideas] duck typing for io write methods

Nick Coghlan ncoghlan at gmail.com
Thu Jun 13 14:24:47 CEST 2013


On 13 June 2013 21:30, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
> I find it very strange that you cannot override the superclass behavior,
> when you can override e.g. the __str__ method in any subclass of str.

If your type is acceptable input to operator.index(), you'll get the
"initialised array of bytes" behaviour, and the custom str handling is
triggered off a simple isinstance() check. It's part of the
bytes/bytearray constructor definitions.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list