A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-September/129079.html below:

[Python-Dev] Why not support user defined operator overloading ?

[Python-Dev] Why not support user defined operator overloading ? [Python-Dev] Why not support user defined operator overloading ?张佩佩 zhangpeipei812 at outlook.com
Mon Sep 30 02:23:12 CEST 2013
Hello:
	I agree with Steven D'Aprano.
Here is an example:

class A(object):
	def __init__(self, value):
		self.value = value
	def add(self, other):
		return self.value + other.value
	__magic_method__ = {'+':add}

a1 = A(1)
a2 = A(2)

We only need a macro expand
a1 + a2
to
a1.__magic__method__['+'](a, b)

the later can be execute on Python.

Regards
peipei
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4