Default scope of variables

Peter Otten __peter__ at web.de
Thu Jul 4 14:36:16 EDT 2013


Rotwang wrote:

> Sorry to be OT, but this is sending my pedantry glands haywire:

We are mostly pedants, too -- so this is well-deserved...
 
> On 04/07/2013 08:06, Dave Angel wrote:
>> On 07/04/2013 01:32 AM, Steven D'Aprano wrote:
>>>
>>        <SNIP>
>>>
>>> Well, if I ever have more than 63,000,000 variables[1] in a function,
>>> I'll keep that in mind.
>>>
>>      <SNIP>
>>>
>>> [1] Based on empirical evidence that Python supports names with length
>>> [at
>>> least up to one million characters long, and assuming that each
>>> character can be an ASCII letter, digit or underscore.
>>>
>>
>> Well, the number wouldn't be 63,000,000.  Rather it'd be 63**1000000
>>
>> I probably have it wrong, but I think that looks like:
>>
>> 859,122,[etc.]
>>
>>
>> variables.  (The number has 180 digits)
> 
> That's 63**100. Note that 10**1000000 has 1000001 digits, and is
> somewhat smaller than 63**1000000.
> 
> Anyway, none of the calculations that has been given takes into account
> the fact that names can be /less/ than one million characters long. 

I think we have a winner ;)

> 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

> It's perhaps worth mentioning that some non-ascii characters are allowed
> in identifiers in Python 3, though I don't know which ones.





More information about the Python-list mailing list