Where do nested functions live?

Rob Williscroft rtw at freenet.co.uk
Wed Nov 1 15:55:16 EST 2006


Steve Holden wrote in
news:mailman.1615.1162411287.11739.python-list at python.org in
comp.lang.python: 

> Since we have a class that goes out of scope 
>> when the function returns, and we don't need more than one instance,
>> why bother to make an instance? Why not use the class object itself?
>> 
>> def whatever( new_ms ):
>> 
>>   class scope ( object ):
>> 
>>   def inner():
>>     scope.mseconds = new_ms - s * 1000       
>>     m, scope.seconds = divmod (s, 60)
>>     h, scope.minutes = divmod (m, 60)
>>     d, scope.hours = divmod (h, 24)
>>     scope.weeks, scope.days = divmod (d, 7)     
>> 
> That will need to be
> 
>    class scope(object): pass
> 
> to avoid syntax errors, I suspect. There doesn't seem to be any reason
> why you couldn't use a class instead of an instance. And, of course, 
> either might give you problems in the case of a recursive inner
> function. 

What problems would it have that a recursive global function 
that modified a global object, or a recursive method that 
modified its instance doesn't have ?

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list