Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'example:': 0.03; 'inspired': 0.05; 'ascii': 0.09; 'categories.': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '"x"': 0.16; 'identifier.': 0.16; 'identifiers': 0.16; 'infinity': 0.16; 'non-ascii': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'underscores,': 0.16; 'url:peps': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'url:dev': 0.24; 'question': 0.24; 'possibly': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'appear': 0.29; 'correct': 0.29; 'characters': 0.30; "i'm": 0.30; 'code': 0.31; '+0100,': 0.31; "d'aprano": 0.31; 'long.': 0.31; 'ones.': 0.31; 'piece': 0.31; 'steven': 0.31; 'stuff': 0.32; 'url:python': 0.33; 'actual': 0.34; 'there,': 0.34; 'something': 0.35; 'definition': 0.35; 'but': 0.35; 'there': 0.35; 'consist': 0.36; 'false': 0.36; 'method': 0.36; 'url:org': 0.36; 'starting': 0.37; 'expected': 0.38; 'hat': 0.38; 'to:addr:python- list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'skip:u 10': 0.60; 'truly': 0.60; 'most': 0.60; 'length': 0.61; 'url:3': 0.61; 'more': 0.64; 'account': 0.65; 'worth': 0.66; 'sample': 0.67; 'capital': 0.73; 'jul': 0.74; 'million': 0.74; 'sir,': 0.81; 'calculations': 0.84; 'characters,': 0.84; 'describes': 0.84; 'greek': 0.84; 'url:reference': 0.84; '8bit%:90': 0.93; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Default scope of variables Date: Thu, 04 Jul 2013 22:03:52 -0400 References: <51d4eb9c$0$29999$c3e8da3$5496439d@news.astraweb.com> <51d508ed$0$6512$c3e8da3$5496439d@news.astraweb.com> <51d62039$0$29999$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.34 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 In-Reply-To: <51d62039$0$29999$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372989849 news.xs4all.nl 15934 [2001:888:2000:d::a6]:56130 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49921 On 07/04/2013 09:24 PM, Steven D'Aprano wrote: > On Thu, 04 Jul 2013 17:54:20 +0100, Rotwang wrote: > [...] >> Anyway, none of the calculations that has been given takes into account >> the fact that names can be /less/ than one million characters long. > > > Not in *my* code they don't!!! > > *wink* > > >> The >> actual number of non-empty strings of length at most 1000000 characters, >> that consist only of ascii letters, digits or underscores, and that >> don't start with a digit, is >> >> sum(53*63**i for i in range(1000000)) == 53*(63**1000000 - 1)//62 > > > I take my hat of to you sir, or possibly madam. That is truly an inspired > piece of pedantry. > > >> It's perhaps worth mentioning that some non-ascii characters are allowed >> in identifiers in Python 3, though I don't know which ones. > > PEP 3131 describes the rules: > > http://www.python.org/dev/peps/pep-3131/ > > For example: > > py> import unicodedata as ud > py> for c in '鿥µ¿μЖᚃ‰⇄∞': > ... print(c, ud.name(c), c.isidentifier(), ud.category(c)) > ... > é LATIN SMALL LETTER E WITH ACUTE True Ll > æ LATIN SMALL LETTER AE True Ll > ¥ YEN SIGN False Sc > µ MICRO SIGN True Ll > ¿ INVERTED QUESTION MARK False Po > μ GREEK SMALL LETTER MU True Ll > Ж CYRILLIC CAPITAL LETTER ZHE True Lu > ᚃ OGHAM LETTER FEARN True Lo > ‰ PER MILLE SIGN False Po > ⇄ RIGHTWARDS ARROW OVER LEFTWARDS ARROW False So > ∞ INFINITY False Sm > > > The isidentifier() method will let you weed out the characters that cannot start an identifier. But there are other groups of characters that can appear after the starting "letter". So a more reasonable sample might be something like: > py> import unicodedata as ud > py> for c in '鿥µ¿μЖᚃ‰⇄∞': > ... xc = "X" + c > ... print(c, ud.name(c), xc.isidentifier(), ud.category(c)) > ... In particular, http://docs.python.org/3.3/reference/lexical_analysis.html#identifiers has a definition for id_continue that includes several interesting categories. I expected the non-ASCII digits, but there's other stuff there, like "nonspacing marks" that are surprising. I'm pretty much speculating here, so please correct me if I'm way off. -- DaveA