Default scope of variables

Neil Cerutti neilc at norwich.edu
Fri Jul 5 09:24:43 EDT 2013


On 2013-07-04, Dave Angel <davea at davea.name> 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

You should really count only the ones somebody might actually
want to use. That's a much, much smaller number, though still
plenty big.

Inner scopes (I don't remember the official name) is a great
feature of C++. It's not the right feature for Python, though,
since Python doesn't have deterministic destruction. It wouldn't
buy much except for namespace tidyness.

for x in range(4):
   print(x)
print(x) # Vader NOoooooOOOOOO!!!

Python provides deterministic destruction with a different
feature.

-- 
Neil Cerutti



More information about the Python-list mailing list