Skip to content

Instantly share code, notes, and snippets.

@zhusimaji
Created August 8, 2018 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhusimaji/df879dd537a6729b6201f456e2c08b71 to your computer and use it in GitHub Desktop.
Save zhusimaji/df879dd537a6729b6201f456e2c08b71 to your computer and use it in GitHub Desktop.
class Proxy:
def __init__(self, obj):
self._obj = obj
def __getattr__(self, item):
#这里的毛病
return getattr(self._obj, item)
class Spam:
def __init__(self, x):
self.x = x
def bar(self, y):
print('Spam.bar:', self.x, y)
if __name__ == "__main__":
spam = Spam(10.05)
proxy = Proxy(spam)
print(proxy.x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment