accessing a functions var from a subfunction.

Duncan Booth duncan at
Mon Apr 14 16:37:18 CEST 2003

seppi at (Sebastian Wilhelmi) wrote in 
news:a3cae241.0304140616.1833e5c4 at

> Now my question: Is there some way to achieve this with a nicer
> syntax?

The usual way is to define a class and store your counter in the class.
You don't actually *have* to use nested functions everywhere.

class Counter:
    def __init__(self):
        self.count = 0
    def inc(self):
        self.count += 1
    def show(self):
        print self.count

def test():
    c = Counter()

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list