parse <class 'gluon.storage.Storage'>

37 views
Skip to first unread message

Pierre

unread,
May 19, 2016, 10:58:56 AM5/19/16
to web2py-users
Hi,

I have a variable  r = request.post_vars of the form { 'a':1, 'b':2, 'ab': { 'aba':10 , 'abb':20 }  }

it's a gluon.storage.Storage object. how do I extract r['ab']    ?

this doesn't work :  r.pop('ab',None) ,  r.ab ,  r['ab']['aba'] ,   r.ab.aba

Anthony

unread,
May 19, 2016, 11:08:51 AM5/19/16
to web2py-users
Are you sure you have the structure correct? How is it populated, and what do you get when you print it?

Pierre

unread,
May 19, 2016, 11:52:50 AM5/19/16
to web2py-users

here is the view output displaying the object


r:
address:
17 Rue Farges, 13008 Marseille, France
admlev_one:
Provence-Alpes-Côte d'Azur
admlev_two:
Bouches-du-Rhône
country:
FR
latlon[lat]:
43.2806116
latlon[lon]:
5.384511599999996
locality:
Marseille
postalcode:
13008
t:
<class 'gluon.storage.Storage'>

it's well parsed 'latlon' is nested as 'ab' in the example above
how do I print it /where ?

Anthony

unread,
May 19, 2016, 1:06:28 PM5/19/16
to web2py-users
Looks like maybe whatever process generates the post request is representing a nested data structure via brackets -- so the key "latlon[lat]" is meant to represent an object like {'latlon': {'lat': the_value}}. However, web2py doesn't know to parse keys containing brackets into a nested data structure, so it just takes the key as is. You can probably access the relevant value via request.post_vars['latlon[lat]'].

Anthony

Pierre

unread,
May 19, 2016, 1:54:22 PM5/19/16
to web2py-users
ok
I'll flatten the object     and I expect it's not going to complain.........

thanks Anthony
Reply all
Reply to author
Forward
0 new messages