Hi! The whole "pythonic or not pythonic" is silly IMO. Python gives us freedom. Yes, you can do stupid things, but this feature is cool and useful, so why not? And "it's not pythonic" is not an argument at all. They should point out bad things that could happen. Maybe there are some bad edge cases, maybe you care about performance hits, maybe something else, maybe, but if no one has a valid point, "not pythonic" shouldn't be either.
Now, two things: 1. In web2py, you can use Storage (from gluon.storage import Storage). 2. In regular python world, there are other implementations, such as attrdict: https://pypi.python.org/pypi/attrdict/0.5.1 (haven't tried, but should work very similar) Marin On Sat, Sep 6, 2014 at 9:31 AM, Robin Manoli <[email protected]> wrote: > > Hey, > 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. > > 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. 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. > > Now in web2py these objects (session, request.vars) are used as predefined > instances -- they are not normally used for making your own instances. This > way they could be their own type of class (I didn't look into it). Perhaps > this keeps things pythonic, or did you web2py developers find a pythonic > and sustainable way to create your own dict objects? > > Ps. Even though I could think of ways to deal with the issue of shared > attributes, I wouldn't really like to write a new class, as there are many > cases which need to be handled. > > -- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

