Well, I finally ran into a Python Unicode problem, sort of

eryk sun eryksun at gmail.com
Sun Jul 3 19:46:26 EDT 2016


On Sun, Jul 3, 2016 at 6:58 AM, John Ladasky <john_ladasky at sbcglobal.net> wrote:
> The nabla symbol (∇) is used in the naming of gradients. Python isn't having it.
> The interpreter throws a "SyntaxError: invalid character in identifier" when it
> encounters the ∇.

Del is a mathematical operator to take the gradient. It's not part of
the name. For `∇f`, the operator is `∇` and the function name is `f`.
Python lacks a mechanism to add user-defined operators. (R has this
capability.) Maybe this feature could be added. To make parsing
simple, user-defined operators could be limited to non-ASCII symbol
characters (math and other -- Sm, So). That simple option is off the
table if we allow symbol characters in names.

Adding an operator to the language itself requires a PEP. Recently PEP
465 added an `@` operator for matrix products. For example:

    >>> x = np.array([1j, 1])
    >>> x @ x
    0j
    >>> x @ x.conj() # Hermitian inner product
    (2+0j)

Note that using a non-ASCII operator was ruled out:

http://legacy.python.org/dev/peps/pep-0465/#choice-of-operator



More information about the Python-list mailing list