News for hackers. Stuff that matters.
Re:Python Tips and Traps by rnhmjoj on Monday January 19, 2015 @07:31PM (#8914873)

  from collections import defaultdict

  defaultobj = lambda: type('defaultobj', (defaultdict,), {
      '__getattr__': lambda self, x:    self.__getitem__(x),
      '__setattr__': lambda self, x, v: self.__setitem__(x, v)
      })(defaultobj)

  names = defaultobj()
  names.mammalia.primates.homo['H. Sapiens'] = 'Human being'

  print(names)
The same but also allows dot notation.

There are no comments on this comment yet.