Last active
December 16, 2015 08:09
-
-
Save radiosilence/5403824 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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