accessing a functions var from a subfunction.
Duncan Booth
duncan at NOSPAMrcp.co.uk
Mon Apr 14 10:37:18 EDT 2003
seppi at seppi.de (Sebastian Wilhelmi) wrote in
news:a3cae241.0304140616.1833e5c4 at posting.google.com:
> 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.
e.g.
class Counter:
def __init__(self):
self.count = 0
def inc(self):
self.count += 1
def show(self):
print self.count
def test():
c = Counter()
c.inc()
c.inc()
c.show()
--
Duncan Booth duncan at rcp.co.uk
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