> > It is much more clean to write *session.var* than *session['var']* when I > can, as well as *if session.var* instead of *if hasattr(session, 'var')*, > and I would like to use this style of coding generally in python, if it can > remain pythonic. >
Note, session, request, and response are just instances of the gluon.storage.Storage class, which itself inherits from the built-in Python dict. If you like it as is, then I would suggest just using it as is: from gluon.storage import Storage mystorage = Storage() mystorage.myvalue = 'some value' Nothing prevents you from using that outside of a web2py app. I've been looking into using classes to store values, just like for example > session does in web2py. I found on stack overflow that it might not be > pythonic, it is not recommended by some experienced programmers. > Not sure what that means. Can you share specific arguments made against specific implementations? Links to SO? Note, the web2py Storage class is just a Python dict tweaked to allow setting/getting via either keys or attributes and to return None when a non-existent key is accessed (rather than raising an exception). Otherwise, it is just a dict. > After trying many ways to do this, none of the ways I tried created > classes with instances. In other words, if I would make two instances of my > class they would share attribute values. Setting *myobject2.var* would > also set *myobject.var* to the same value. > Sounds like you are setting class attributes. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.