Can someone please tell me the difference between
urls = (
"/count", "count",
"/reset", "reset")
app = web.application(urls, locals())
store = web.session.DiskStore('sessions')
session = web.session.Session(app, store, initializer={'count': 0})
class count:
def GET(self):
session.count += 1
return str(session.count)
class reset:
def GET(self):
session.kill()
return ""
if __name__ == "__main__":
app.run()
and
urls = (
"/count", "count",
"/reset", "reset")
app = web.application(urls, locals())
class count:
counting = 0
def GET(self):
count.counting += 1
return str(count.counting)
class reset:
def GET(self):
count.counting = 0
return ""
if __name__ == "__main__":
app.run()
Both their output is exactly the same as far as I can tell. If there is no difference then what is the advantage of using Session objects over variables like this ?
I am pretty new to Python and going through Zed Shaw's Learn Python the Hard Way. I was on exercise 52 where he introduces sessions when this question popped into my head.