Default scope of variables

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jul 5 03:24:09 CEST 2013


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



-- 
Steven



More information about the Python-list mailing list