Re: accessing local and global dictionaries

Harri Pasanen (pa@tekla.fi)
Wed, 1 Mar 1995 23:35:30 +0200

Guido van Rossum writes:
> > # Example usage: define globals a,b and c, starting from 2.
> > enum('a,b,c', 2)
>
> This is accomplished just as easy using
>
> [a, b, c] = range(2, 2+3)

This is what enum does internally.

Modification is not quite as easy, as I now have to modify both
sides of the equation mark if I want to add variables.

enum('a, b, c, d', 2) vs. [a, b, c, d] = range(2, 2+4)
^ ^ ^
If the list of identifiers is long, it becomes difficult trying to
track down the length of the list that must be added manually to the
range. (I'm just trying to mimic part of what enum { a = 2, b, c, d,
... } does in C.)

But my actual question concerned deciphering the dictionaries for
different scopes. Any pointers there?

>
> No 'enum()' function needed at all! (And the advantage is that the
> optimizer knows which identifiers you are defining.)
>

I don't understand what you imply about the optimizer. Are you saying
that because these variables go into global scope, which is always
looked at last, it is slower to access them?

But if I want these identifiers to be global, I would think that both

enum('a, b, c', 2)

and

[a, b, c] = range(2, 2+3)

would create performance-wise equal variables. Am I missing something?

Execution of enum() is of course bound to be slower than the more
direct range usage.

Take Care,

Harri