You cannot store your own classes in the session. This is because the
session is retrieved automatically for you before your controller is
called and outside the scope where the function is defined.

This is a general problem with Python.

Try this:
import picke
class A: pass
pickle.dump(A(),open('afile.pickle','w'))

Then from a DIFFERENT program
import pickle
print pickle.load(open('afile.pickle','r))

the load will fail because class A is not define there.

Massimo

On May 13, 12:14 am, lesh <markl...@marklesh.com> wrote:
> I am having difficulty storing a simple (non-SQL) object in the
> session. I wondered if anyone could give me a clue as to why. The
> following works:
>
> def update_profile():
>     if (session.sections!=None):
>         session.sections=None
>         return dict(sections='spam')
>     else:
>         session.sections={}
>         #x = testClass()
>         x = 'eggs'
>         session.sections=x
>         return dict(sections=`x`)
>
> class testClass:
>     pass
>
> with a toggling result on successive reloads of:
>
> ' e g g s '
> <<RELOAD THE PAGE>>
> s p a m
> ...
>
> However if I swap the two lines as below:
>
> def update_profile():
>     if (session.sections!=None):
>         session.sections=None
>         return dict(sections='spam')
>     else:
>         session.sections={}
>         x = testClass()
>         #x = 'eggs'
>         session.sections=x
>         return dict(sections=`x`)
>
> class testClass:
>     pass
>
> The result fails to toggle:
>
> <__b u i l t i n__.testClassinstanceat0xab18ccc>
> <<RELOAD THE PAGE>>
> <__b u i l t i n__.testClassinstanceat0xab094cc>
> ...
>
> Which appears that the object doesn't ever actually store into the
> session. I searched the group and from what I can tell this is
> possible, but I can't figure out what I'm doing wrong.
>
> Thanks in advance!
>
>     -- Lesh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to