[Tutor] "farkadoodle" or: unique global names, was Re: Data persistence problem

Jim Mooney cybervigilante at gmail.com
Mon Jun 24 04:38:45 CEST 2013


On 22 June 2013 19:24, Steven D'Aprano <steve at pearwood.info> wrote:

> * If you assign to a name (e.g. "spam = 42") anywhere inside the body of a
> function, then that name is treated as a local variable, which is a fast
> lookup.
>
> * Otherwise, it is treated as unknown scope, and Python will search nesting
> functions (if any), globals, and finally builtins for the name.

What about class variables instead of globals?, I put this in the my
lazy typer module, maker.py, which works fine to persist the numbers
between function calls so I can increment them:

class count:
    dict = list = set = tuple = 0

then I use count.dict += 1 , etc.

Would that restrict python from an upward search, or am I dreaming?

And yes, I got rid of the Basic-style names D1, D2. The program now
converts numbers to human-names up to  dict_ninety_nine = , for
instance.  And no, I didn't type ninety_nine dictionary entries to do
that. I'm too lazy a typer  ;')

-- 
Jim
Resistance is futile, but running away is often surprisingly effective.


More information about the Tutor mailing list