Skip to content

Instantly share code, notes, and snippets.

@sirpengi
Created September 27, 2014 18:23
Show Gist options
  • Save sirpengi/09c65fa09f57650d1beb to your computer and use it in GitHub Desktop.
Save sirpengi/09c65fa09f57650d1beb to your computer and use it in GitHub Desktop.
yolodb
class YOLODBType(object):
pass
def YOLODB():
class val():
v = None
def _T(f, c, g, is_root=False):
class T(YOLODBType):
def __str__(self):
return str(g.v)
def __repr__(self):
return repr(g.v)
def __unicode__(self):
return unicode(g.v)
def __iter__(self):
return iter(v[0] for v in c.values())
def __setattr__(self, k, v):
getattr(self, k)
c[k][1].v = v
def __getattr__(self, k):
if k not in c:
_g = val()
c[k] = (f(f, dict(), _g), _g)
if isinstance(c[k][1].v, YOLODBType):
return c[k][1].v
return c[k][0]
ret = T()
return ret
return _T(_T, dict(), val(), True)
t = YOLODB()
print t
print t.undefined
t.a = "it's a"
t.b = "it's b"
t.c = "it's c"
print t.a
print t.b
print t.c
t.d.people.alice = "it's alice"
t.d.people.bob = "it's bob"
for k in t.d.people:
print k
t.sets.set_a.val = "val in set_a"
t.sets.set_b.val = "val in set_b"
for some_set in t.sets:
print some_set.val
t2 = YOLODB()
t.t2 = t2
print t.t2
t.t2.wow.does.this.work = "yes"
print t2.wow.does.this.work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment