user-defined operators: a very modest proposal

Steve R. Hastings steveha at localhost.localdomain
Wed Nov 23 01:08:41 CET 2005

> 	if [1,2]+[3,4] != [1,2,3,4]: raise TestFailed, 'list concatenation'
> Since it contains ']+[' I assume it must now be parsed as a user-defined
> operator, but this code currently has a meaning in Python.

Yes.  I agree that this is a fatal flaw in my suggestion.

Perhaps there is no syntax that can be done inside the bounds of ASCII
that will please everyone and not break existing code.

Your suggestion of Unicode makes a lot of sense.  There are glyphs for
math operators, and if Python can accept Unicode source files, that seems
to me like a much better solution than hacks involving ASCII characters.

I didn't notice it before, but PEP 263 allows Python source files to be

So the latest versions of Python already have support for Unicode source

Could such Unicode sources be exported to ASCII for porting code to
platforms that don't allow Unicode Python files?  Yes: just replace the
Unicode character with a symbol like __op__, where op is the operator.

Actually, that's a better syntax than the one I proposed, too:

# __add__	# this one's already in use, so not allowed

Steve R. Hastings    "Vita est"
steve at

More information about the Python-list mailing list