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

2013-06-24 Thread Jim Mooney
eryksun > > Oh my. I don't think using the numbers spelled out makes it any > better. I couldn't keep dict_thirty_four vs dict_sixty_five straight > in my head to save my life. It was just for fun. But by coincidence I was trolling the web and some guy wanted to know if Python could change a numb

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

2013-06-24 Thread eryksun
On Sun, Jun 23, 2013 at 10:38 PM, Jim Mooney wrote: > 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 >

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

2013-06-23 Thread Jim Mooney
On 22 June 2013 19:24, Steven D'Aprano 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 > functio

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

2013-06-22 Thread Steven D'Aprano
On 23/06/13 05:59, Albert-Jan Roskam wrote: I was playing around with this a bit and arrived at the following surprising (for me at least) result. I thought the global/local/nonlocal keywords could be used to get values from another scope. Though this could also happen implicitly, e.g. if only

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

2013-06-22 Thread eryksun
On Sat, Jun 22, 2013 at 3:59 PM, Albert-Jan Roskam wrote: > > I was playing around with this a bit and arrived at the following > surprising (for me at least) result. I thought the global/local/nonlocal > keywords could be used to get values from another scope. Though this > could also happen impl

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

2013-06-22 Thread Albert-Jan Roskam
  > One catch with Python nested scopes is that binding a name defaults to > the local scope. You can get around this by using a mutable container, > just as was done with globals before the "global" keyword was added in > version 0.9.4 (1991). The better solution is a new keyword, but adding >

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

2013-06-22 Thread eryksun
On Sat, Jun 22, 2013 at 7:10 AM, Steven D'Aprano wrote: > The function attribute "__closure__" is set to None for regular functions. > For closures, it is set to a bunch of stuff needed for the inner function to > work correctly. (No user serviceable parts inside.) Basically, the inner > function

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

2013-06-22 Thread Steven D'Aprano
On 22/06/13 17:04, Peter Otten wrote: This technique of nesting a function inside another function ("closure") To be pedantic, not all nested functions are closures. Here's one which is not: def outer(arg): def inner(x): return x + 1 assert inner.__closure__ is None return

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

2013-06-22 Thread Peter Otten
Jim Mooney wrote: > dictnumfarkadoodle = listnumfarkadoodle = setnumfarkadoodle = 0 > # Since these are global I'm using words not likely to be duplicated > until I figure a different way and > # replace 'farkadoodle' with '' ;') Name clashes are generally not a problem if (1) you keep module s