Because session is a special object of class gluon.storage.Storage that overrides to the built-in __getattr__ method and refined the meaning of attributes. Basically session is a dicionary and it redefined session.key as session['key'] if 'key' in session else None. Same more request and response. You can do
from gluon.storage import Storage >>> class MyClass(Storage): pass >>> myinstance = MyClass() >>> myinstance.myvariable = 3 >>> print myinstance.myvariable But mind that you may run into problems if your class has methods. On Apr 24, 9:58 am, shukalo83 <[email protected]> wrote: > Hello everyone! > I started reading web2py book 3 days ago and I ran into a following > problem. Discussing the new instance of the class variables like in: > > >>> class MyClass(object): pass > >>> myinstance = MyClass() > >>> myinstance.myvariable = 3 > >>> print myinstance.myvariable > > 3 > > That's all fine but when I try: > > >>> class MyClass(object): pass > >>> myinstance = MyClass() > >>> if not myinstance.myvariable: > > ...: myinstance.myvariable = 1 > ...: else: > ...: myinstance.myvariable += 1 > > I get " AttributeError: 'MyClass' object has no attribute 'myvariable' > " and still this is the mechanism applied in web2py official book > under chapter 3, part "Let's Count" > > def index(): > if not session.counter: > session.counter = 1 > else: > session.counter += 1 > return dict(message="Hello from MyApp", counter=session.counter) > > How;s that possible? > > Thank You > > Boyan > > -- > Subscription settings:http://groups.google.com/group/web2py/subscribe?hl=en

