Skip to content

Instantly share code, notes, and snippets.

@larsbratholm
Last active June 12, 2016 17:35
Show Gist options
  • Save larsbratholm/8d019572051e47d9e128238842193885 to your computer and use it in GitHub Desktop.
Save larsbratholm/8d019572051e47d9e128238842193885 to your computer and use it in GitHub Desktop.
const example
# const decorator
def const(f):
def fset(self, value):
raise TypeError
def fget(self):
return f(self)
return property(fget, fset)
# example with class
class Data(object):
def __init__(self, x):
self._x_init = x
@const
def x(self):
return self._x_init
# will produce error
x = 5
d = Data(x)
d.x = 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment