i'm sorry that doesn't make sense to me. nonetheless, i tried it with different variable names, as:
if 1: ss = Storage(s='main') ss.happy = 'yes happy' print("1:::", ss, type(ss)) s1 = repr(ss) print("2:::", s1, type(s1)) s2 = eval(s1) print("3:::", s2, type(s2)) and i still got the same error: 1::: <Storage {'s': 'main', 'happy': 'yes happy'}> <class 'gluon.storage.Storage'> 2::: <Storage {'s': 'main', 'happy': 'yes happy'}> <class 'str'> Traceback (most recent call last): File "./web2py_Storage.py", line 17, in <module> s2 = eval(s1) File "<string>", line 1 <Storage {'s': 'main', 'happy': 'yes happy'}> ^ SyntaxError: invalid syntax there are so many convertors like to and from json, wouldn't it make sense to and from string for storage? thank you again, lucas On Sunday, April 25, 2021 at 3:07:29 AM UTC-4 snide...@gmail.com wrote: > On Friday, April 23, 2021 at 9:43:19 AM UTC-7 lucas wrote: > >> hello one and all, >> >> i'd like to save and recover Storage instances to a text blob field in a >> database. converting to the string is not hard to store it in the field. >> recovering it back to a Storage instance is other issue, especially when >> they're embedded Storage objects in the main Storage object. i've tried >> from a script file not under a web2py application as: >> >> #!/usr/bin/env python3 >> # -*- coding: utf-8 -*- >> from sys import path, argv >> path.append('/opt/web2py_apps/web2py/') >> from gluon import * >> from gluon.storage import Storage >> if 1: >> ss = Storage(s='main') >> ss.happy = 'yes happy' >> #ss.status = Storage(s1="1status1", s2="2status2") >> print("1:::", ss, type(ss)) >> ss = repr(ss) >> print("2:::", ss, type(ss)) >> #xglobal, xlocal = globals(), { } >> #eval(ss, xglobal, xlocal) >> ss = eval(ss) >> print("3:::", ss, type(ss)) >> exit() >> >> with output: >> 1::: <Storage {'s': 'main', 'happy': 'yes happy'}> <class >> 'gluon.storage.Storage'> >> 2::: <Storage {'s': 'main', 'happy': 'yes happy'}> <class 'str'> >> Traceback (most recent call last): >> File "./web2py_Storage.py", line 17, in <module> >> ss = eval(ss) >> File "<string>", line 1 >> <Storage {'s': 'main', 'happy': 'yes happy'}> >> ^ >> SyntaxError: invalid syntax >> >> any ideas how to make this work smoothly? thank you in advance, lucas >> > > When you convert the storage to string (via the repr() call), don't use > the same name. > > /dps > > > -- 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 web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/ede48cc5-412e-49e3-99f2-5723ba295bebn%40googlegroups.com.