[Tutor] making a random list, then naming it

Dave Angel davea at davea.name
Sat May 25 03:44:10 CEST 2013


On 05/24/2013 09:35 PM, Jim Mooney wrote:
> On 24 May 2013 18:10, Dave Angel <davea at davea.name> wrote:
>
>> Is lists[(3,8)]  really so much harder to type than
>>      list_3_8  ?
>>
>
> You have a point. I hate underlines - my finger always misses them.
> Keyboards were not designed for programming ;')
>
> Anyway, I just thought I'd try exec, but it's giving me fits putting it in
> a function so I can do multiple lists. A dictionary looks more manageable.
>
> Jim
>

Just to save you further frustration, CPython compiles a function in 
such a way that adding new local identifiers to the function is 
effectively impossible.  The compiler decided long before the function 
is run how many locals there are, and what they're called.

So some sneaky tricks that work at global level won't work inside a 
function.

Other Python implementations may have other gotchas.  But a dict is 
legal in all of them.

-- 
DaveA


More information about the Tutor mailing list