To access a global variable, you have to use the global
keyword followed by the name of the variable. However, if r
is going to be used only in the Root
class, I recommend you to declare it as a class variable:
class Root(object):
r = 1
@cherrypy.expose
def index(self, **params):
#...
if Root.r != 1:
Root.r += 1
#...