operator module functions

Ethan Furman ethan at stoneleaf.us
Wed Oct 8 23:49:00 CEST 2014


[redirecting back to the list]

On 10/08/2014 02:23 PM, random832 at fastmail.us wrote:
> On Wed, Oct 8, 2014, at 15:53, Ethan Furman wrote:
>> On 10/08/2014 12:49 PM, random832 at fastmail.us wrote:
>>> On Wed, Oct 8, 2014, at 15:38, Ethan Furman wrote:
>>>>
>>>> LOL, no kidding!  The main reason I bother using the operator module is
>>>> for the readability of not seeing the dunders,
>>>> and the writability of not having to type them.
>>>
>>> I'm not sure what situation you would have to type them (as opposed to
>>> simply a + b) that the operator module would help with.
>>
>> unittest springs to mind:
>>
>>     self.assertRaises(TypeError, op.add, obj1, obj2)
>
> Er, my point is, that is not a situation where you would be able to use
> obj1.__add__ - you'd have to use the operator module *anyway*, and
> therefore aren't using it just to get the convenience of a non-dunder
> name.

  self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2)

--
~Ethan~



More information about the Python-list mailing list