Skip to content

Instantly share code, notes, and snippets.

@radiosilence
Last active December 16, 2015 08:09
Show Gist options
  • Save radiosilence/5403824 to your computer and use it in GitHub Desktop.
Save radiosilence/5403824 to your computer and use it in GitHub Desktop.
class Account(object):
address1 = '1 Potato Street'
billing_address1 = None
name = 'John Doe'
billing_name = 'Jane Doe'
@property
def billing(self):
account = self
class c:
def __getattr__(self, name):
return getattr(account, 'billing_' + name) \
or getattr(account, name)
return c()
account = Account()
print account.address1
# 1 Potato Street
print account.billing.address1
# 1 Potato Street
print account.name
# John Doe
print account.billing.name
# Jane Doe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment