Hi bumsfeld,
Well, let's think about this. Suppose that we want to create a variable 'count' that records the number of times a function 'myfunc()' is called. If the variable's scope is limited to the function itself, it will disappear off the runtime stack when the function call is completed. Any way you shake it, we're going to need some kind of globalesque way of maintaining count, even if we don't create global variables with the 'global' keyword, per se.
Any of these solutions qualify as globalesque, and most of them are horribly contrived:
* You could keep the count in a text file (ugh! overhead).
* You could keep a separate thread running which polls the main thread of execution.
* You could give each function its own count attribute, and update those attributes in a separate bookie function.
The last solution is essentially the same as collecting global variables, except each is bound to the appropriate function, which is nice. It would look something like this:
def bookie(func):
func.count += 1
def myfunc():
bookie(myfunc)
# Some other code goes here
myfunc.count = 0
for i in range(10):
myfunc()
print myfunc.count # Should give you 10
But I can think of no means of doing this without variables belonging to some kind of global scope.