[web2py] Re: Why not session['key'] ?

2010-05-12 Thread ionel
Ok, I understand. I create a session variable with session.my_var = some content but not with session['some_id'] = some content (web2py will raise an exception if the session variable does not exists), and I get the content with another_var = session.my_var or another_var = session['my_var']

Re: [web2py] Re: Why not session['key'] ?

2010-05-12 Thread Thadeus Burgess
session['fav_color'] = blue works just fine. session is just a gluon/storage.Storage() class. which is a subclass of dict and it only provides an extra method to give you the attribute access to make things easier. Otherwise works exactly like any other python dictionary. You can use the session

[web2py] Re: Why not session['key'] ?

2010-05-12 Thread ionel
Yes, you are right! I was creating the session variable in the View, not in the Controller. Oh, poor me! This is my ASP background. There I can create a session variable anywhere. Thanks. ionel On May 13, 12:02 am, Thadeus Burgess thade...@thadeusb.com wrote: session['fav_color'] = blue works

[web2py] Re: Why not session['key'] ?

2010-05-12 Thread mdipierro
You can create it in the view in web2py. It is not a good idea. It would not be visible in the model and controller until reload. On May 12, 11:20 pm, ionel ionelanton...@gmail.com wrote: Yes, you are right! I was creating the session variable in the View, not in the Controller. Oh, poor me!

Re: [web2py] Re: Why not session['key'] ?

2010-05-09 Thread Thadeus Burgess
The reason is session.button1 returns None if the key is not found whereas session['button1'] raises an exception when the key is not found. This is typically python behavior. -- Thadeus On Sat, May 8, 2010 at 11:44 PM, ionel ionelanton...@gmail.com wrote: I think I found a bug.

[web2py] Re: Why not session['key'] ?

2010-05-09 Thread ionel
Thank you. I didn't know :) I'm still a python noob, I think. On May 9, 2:03 am, Thadeus Burgess thade...@thadeusb.com wrote: The reason is session.button1 returns None if the key is not found whereas session['button1'] raises an exception when the key is not found. This is

[web2py] Re: Why not session['key'] ?

2010-05-09 Thread ionel
But anyway, I have an ASP.NET background. Session[key] = value is normal. In PHP also: $_SESSION['views'] = $value; I see this as a limitation because I cannot persist an object into a session( if the session file it's not created) with a variable as key. For example: some_id = 'my_id'

[web2py] Re: Why not session['key'] ?

2010-05-08 Thread mdipierro
You cannot store your own classes in the session because the session is retrieved before your own classes are defined. You can only store in session primitive types. You can serialize your objects yourself. On May 8, 7:30 pm, ionel ionelanton...@gmail.com wrote: Hello, I'd like to have

[web2py] Re: Why not session['key'] ?

2010-05-08 Thread ionel
But I allready did that... and its working... Something like that: if not session.c: c = MyClass() session.c = c else: c = session.c But my question was why I cannot use session['c'] instead of session.c Thank you! i On May 8, 9:31 pm, mdipierro mdipie...@cs.depaul.edu wrote:

[web2py] Re: Why not session['key'] ?

2010-05-08 Thread mdipierro
They should be equivalent. Can you show the traceback? On May 8, 9:54 pm, ionel ionelanton...@gmail.com wrote: But I allready did that... and its working... Something like that: if not session.c:     c = MyClass()     session.c = c else:     c = session.c But my question was why I