Another way to solve this problem is that we could define a new class and try to emulate dict. It's dummy because you have to re-implement all dict methods yourself, but it works. The code looks like this:
class Storage(): def __getattr__(self, key): try: return self.__dict__[key] except: return None def __getitem__(self, key): try: return self.__dict__[key] except: return None def __setattr__(self, key, value): read_only_methods = ['clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'] if key in read_only_methods: raise AttributeError("attribute '%s' is read-only" % key) self.__dict__[key] = value def clear(self): self.__dict__ = dict() def copy(self): dup = Storage() dup.__dict__ = self.__dict__.copy() return dup ... ... ... -- Luyun Xie 谢路云 http://magefromhell.blogspot.com/ (http://blog.hellmage.info/) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" 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 -~----------~----~----~----~------~----~------~--~---