Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110983

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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Well, I finally ran into a Python Unicode problem, sort of
Date Sun, 3 Jul 2016 17:41:59 +1000
Lines 56
Message-ID <mailman.36.1467531722.2295.python-list@python.org> (permalink)
References <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <CAPTjJmpXygTHwzMzPFtU96eanS_0GQvo1L4cYgEfqUa_HfGSOQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de gkzgbiYFmKgnvWpXmXp04QgrA8FQvqN+J+/K4YybsnOQ==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'cpython': 0.05; 'defines': 0.07; 'cc:addr:python-list': 0.09; 'derived': 0.09; 'identifier': 0.09; 'identifier,': 0.09; 'inclusion': 0.09; 'non-ascii': 0.09; 'subject:into': 0.09; 'throws': 0.09; 'python': 0.10; 'question.': 0.13; 'interpreter': 0.15; 'weird': 0.15; "(it's": 0.16; '2016': 0.16; 'alphabet': 0.16; 'constitutes': 0.16; 'devs': 0.16; 'formula': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identifiers,': 0.16; 'naming': 0.16; 'obviously,': 0.16; 'operators.': 0.16; 'permits': 0.16; 'properties,': 0.16; 'python- based': 0.16; 'range,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Unicode': 0.16; 'sure.': 0.16; 'wrote:': 0.16; 'refers': 0.18; 'hack': 0.18; 'variable': 0.18; 'language': 0.19; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; "aren't": 0.22; 'subject:problem': 0.22; 'defined': 0.23; 'bit': 0.23; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; "i've": 0.25; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'idea': 0.28; 'skip:u 20': 0.28; 'looks': 0.29; 'category:': 0.29; 'operators': 0.29; 'symbols': 0.29; 'character': 0.29; "i'm": 0.30; 'work.': 0.30; 'probably': 0.31; 'certain': 0.31; "can't": 0.32; 'core': 0.32; 'though,': 0.32; 'maybe': 0.33; 'problem': 0.33; 'url:python': 0.33; 'symbol': 0.33; 'equal': 0.34; 'file': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'could': 0.35; 'besides': 0.35; 'unicode': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'url:org': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'agree': 0.37; 'there,': 0.37; 'starting': 0.37; 'someone': 0.38; 'copying': 0.38; 'why': 0.39; 'sure': 0.39; 'where': 0.40; 'some': 0.40; 'url:3': 0.60; 'john': 0.61; 'today,': 0.62; 'here.': 0.62; 'leaving': 0.63; 'more': 0.63; 'here:': 0.63; 'debate': 0.66; "they're": 0.66; 'here': 0.66; 'letters': 0.67; 'jul': 0.72; 'chrisa': 0.84; 'encounters': 0.84; 'greek': 0.84; 'latin': 0.84; 'question!': 0.84; 'western': 0.89; 'to:none': 0.91; 'url:reference': 0.91; 'grey': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc :content-transfer-encoding; bh=TD3CHKpdYURtroz9x1dDxednFjJW3o1BMFnI9ECSKP4=; b=O1wbU+UKCeiIS3paSD/yuH64eCsO+m8GuuWGYMBX8FkCaz0kgGhGSM8E7iqzTv5Ndj mlgphLyHipENgvgpkIkxdmJokA+USixDuBWLY/OfCQP+qYKIeRZV+NxVORVbyGpZFBgd fGOUiydedN43UJOAq7uDnYMgW7/26w463qKtQahbTHLJncmLDVmJq/VhNIWmZUEghoUm GpAFoXp0nWKfE01aqROcuwJM8pjoEP4LoUE+vEEdsIxKic7c7UEjY91hQjCht7Y0UdEj 6NWrwRsj5DJ0TMtcM/Cot2OepMu+X7iF875+IBsotR1XqHoRadqkn8eNENm1nMzlbHpA 5BrA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc:content-transfer-encoding; bh=TD3CHKpdYURtroz9x1dDxednFjJW3o1BMFnI9ECSKP4=; b=AARD7PktzjSXZnN2M4qbbE1J0FWR9pnIz9mWNg98/LbbQ7ixn+lxppBpPJ2fy6e6fL /4A/Lqd1ebsb0PDsjqvwKWg0xPcJYZuIm9USPtoh0vNcoLAaarcGX0tp+1CjYIqtkBv6 Od1WEkvy3eLg1U4gejmbncCxrH96gHIiebDUwPpcVbbe8856nqPllTSreUM1QnBdwv0m TWdzPGSiH0JoK1/5BilASUv3GrUYYCXlgElBk8VW38oUOk7o21X3BYsz/wUn9H0GDyLu i6VbC0spuGDSxAGVrjoa//E+Ye6zcTXJLhTk/xnpyQQrvCasM+WGAW5Im6zU9cdrNg6J aT2g==
X-Gm-Message-State ALyK8tKaAMVZCJrP2QO3fb4W9BaYnZO8sNnIfAPbZgrucurqHaU69dlIN3JZN9Evc5BxvL3lsKCviHm7Ai4XlA==
X-Received by 10.194.70.41 with SMTP id j9mr5224707wju.30.1467531719835; Sun, 03 Jul 2016 00:41:59 -0700 (PDT)
In-Reply-To <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAPTjJmpXygTHwzMzPFtU96eanS_0GQvo1L4cYgEfqUa_HfGSOQ@mail.gmail.com>
X-Mailman-Original-References <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com>
Xref csiph.com comp.lang.python:110983

Show key headers only | View raw


On Sun, Jul 3, 2016 at 4:58 PM, John Ladasky <john_ladasky@sbcglobal.net> wrote:
> Up until today, every character I've tried has been accepted by the Python interpreter as a legitimate character for inclusion in a variable name.  Now I'm copying a formula which defines a gradient.  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 ∇.
>
> I am now wondering what constitutes a valid character for an identifier, and how they were chosen.  Obviously, the Western alphabet and standard Greek letters work.  I just tried a few very weird characters from the Latin Extended range, and some Cyrillic characters.  These are also fine.
>

Very good question! The detaily answer is here:

https://docs.python.org/3/reference/lexical_analysis.html#identifiers

> A philosophical question.  Why should any character be excluded from a variable name, besides the fact that it might also be an operator?
>

In a way, that's exactly what's happening here. Python permits certain
categories of character as identifiers, leaving other categories
available for operators. Even though there aren't any non-ASCII
operators in a vanilla CPython, it's plausible that someone could
create a Python-based language with more operators (eg ≠ NOT EQUAL TO
as an alternative to !=), and I'm sure you'd agree that saying "≠ = 1"
is nonsensical.

> This might be a problem I can solve, I'm not sure.  Is there a file that the Python interpreter refers to which defines the accepted variable name characters?  Perhaps I could just add ∇.
>

The key here is its Unicode category:

>>> unicodedata.category("∇")
'Sm'

You could probably hack CPython to include Sm, and maybe Sc, Sk, and
So, as valid identifier characters. I'm not sure where, though, and
I've just spent a good bit of time delving (it's based on the
XID_Start and XID_Continue derived properties, but I have no idea
where they're defined - Tools/unicode/makeunicodedata.py looks
promising, but even there, I can't find it). And - or maybe instead -
you could appeal to the core devs to have the category/ies in question
added to the official Python spec. Symbols like that are a bit of a
grey area, so you may find that you're starting a huge debate :)

Have fun.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Well, I finally ran into a Python Unicode problem, sort of John Ladasky <john_ladasky@sbcglobal.net> - 2016-07-02 23:58 -0700
  Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 00:07 -0700
    Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-03 10:26 +0300
      Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 01:38 -0700
        Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-03 12:01 +0300
          Re: Well, I finally ran into a Python Unicode problem, sort of Chris Angelico <rosuav@gmail.com> - 2016-07-04 01:14 +1000
          Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 14:21 -0700
    Re: Well, I finally ran into a Python Unicode problem, sort of John Ladasky <john_ladasky@sbcglobal.net> - 2016-07-03 09:24 -0700
  Re: Well, I finally ran into a Python Unicode problem, sort of Rustom Mody <rustompmody@gmail.com> - 2016-07-03 00:26 -0700
  Re: Well, I finally ran into a Python Unicode problem, sort of Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-07-03 10:29 +0300
    Re: Well, I finally ran into a Python Unicode problem, sort of Robert Kern <robert.kern@gmail.com> - 2016-07-03 10:16 +0100
  Re: Well, I finally ran into a Python Unicode problem, sort of Chris Angelico <rosuav@gmail.com> - 2016-07-03 17:41 +1000
    Re: Well, I finally ran into a Python Unicode problem, sort of John Ladasky <john_ladasky@sbcglobal.net> - 2016-07-03 11:39 -0700
      Re: Well, I finally ran into a Python Unicode problem, sort of MRAB <python@mrabarnett.plus.com> - 2016-07-03 20:41 +0100
      Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 14:28 -0700
        Re: Well, I finally ran into a Python Unicode problem, sort of Steven D'Aprano <steve@pearwood.info> - 2016-07-04 12:33 +1000
          Re: Well, I finally ran into a Python Unicode problem, sort of Rustom Mody <rustompmody@gmail.com> - 2016-07-03 22:14 -0700
            Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-04 01:11 -0700
              Re: Well, I finally ran into a Python Unicode problem, sort of Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-07-04 13:10 +0300
              Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-04 12:04 +0300
            Re: Well, I finally ran into a Python Unicode problem, sort of Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-07-04 09:08 +0300
  Re: Well, I finally ran into a Python Unicode problem, sort of Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2016-07-03 11:53 +0200
    Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-03 14:01 +0300
      Re: Well, I finally ran into a Python Unicode problem, sort of Christian Gollwitzer <auriocus@gmx.de> - 2016-07-03 13:16 +0200
        Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-03 14:22 +0300
          Re: Well, I finally ran into a Python Unicode problem, sort of Christian Gollwitzer <auriocus@gmx.de> - 2016-07-03 16:05 +0200
            Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-03 17:39 +0300
          Re: Well, I finally ran into a Python Unicode problem, sort of Random832 <random832@fastmail.com> - 2016-07-03 16:49 -0400
            Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-04 00:25 +0300
      Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-03 12:50 +0100
        Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 14:26 -0700
  Re: Well, I finally ran into a Python Unicode problem, sort of eryk sun <eryksun@gmail.com> - 2016-07-03 23:46 +0000
    Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 17:00 -0700
      Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-04 01:17 +0100
        Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 17:24 -0700
          Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-04 01:39 +0100
            Re: Well, I finally ran into a Python Unicode problem, sort of Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 18:15 -0700
              Re: Well, I finally ran into a Python Unicode problem, sort of Random832 <random832@fastmail.com> - 2016-07-03 22:20 -0400
              Re: Well, I finally ran into a Python Unicode problem, sort of Rustom Mody <rustompmody@gmail.com> - 2016-07-04 05:16 -0700
              Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-04 11:26 +0100
        Re: Well, I finally ran into a Python Unicode problem, sort of Steven D'Aprano <steve@pearwood.info> - 2016-07-04 12:30 +1000
          Re: Well, I finally ran into a Python Unicode problem, sort of Ned Batchelder <ned@nedbatchelder.com> - 2016-07-04 05:47 -0700
            Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-04 15:36 +0100
              Re: Well, I finally ran into a Python Unicode problem, sort of Ned Batchelder <ned@nedbatchelder.com> - 2016-07-04 07:46 -0700
                Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-04 17:16 +0100
                Re: Well, I finally ran into a Python Unicode problem, sort of Marko Rauhamaa <marko@pacujo.net> - 2016-07-04 19:44 +0300
          Re: Well, I finally ran into a Python Unicode problem, sort of BartC <bc@freeuk.com> - 2016-07-04 11:05 +0100
            Re: Well, I finally ran into a Python Unicode problem, sort of Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-07-04 13:26 +0300
      Re: Well, I finally ran into a Python Unicode problem, sort of Random832 <random832@fastmail.com> - 2016-07-03 22:16 -0400

csiph-web