Skip to content

Instantly share code, notes, and snippets.

@appositum
Created April 21, 2018 07:14
Show Gist options
  • Save appositum/903449160e551846ec285dc21401997a to your computer and use it in GitHub Desktop.
Save appositum/903449160e551846ec285dc21401997a to your computer and use it in GitHub Desktop.
class Pointer(object):
def __init__(self, target=None):
self.target = target
_noarg = object()
def __call__(self, target=_noarg):
if target is not self._noarg:
self.target = target
return self.target
x = Pointer(2)
y = x
x() # => 2
y() # => 2
y(30)
x() # => 30
x(50)
y() # => y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment