Skip to content

Instantly share code, notes, and snippets.

@jamesfe
Created May 31, 2016 19:08
Show Gist options
  • Select an option

  • Save jamesfe/c723c148dfb516405b616fd06a93b499 to your computer and use it in GitHub Desktop.

Select an option

Save jamesfe/c723c148dfb516405b616fd06a93b499 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class X(object):
things = {
'a': 1,
'b': 2,
'c': 3
}
def __getattr__(self, attr):
if attr in self.things:
return self.things[attr]
else:
return super(X, self).__getattr__(attr)
test_item = X()
print test_item.a
print test_item.b
print X.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment