Skip to content

Instantly share code, notes, and snippets.

@gevorgyana
Created December 24, 2020 10:01
Show Gist options
  • Save gevorgyana/0ae81740f750127916e60a4ca17b4d93 to your computer and use it in GitHub Desktop.
Save gevorgyana/0ae81740f750127916e60a4ca17b4d93 to your computer and use it in GitHub Desktop.
class Descriptor:
def __get__(self, instance, *args):
return getattr(instance, self.attribute_name, 'None')
def __set__(self, instance, value):
setattr(instance, self.attribute_name, value)
def __delete__(self, instance):
delattr(instance, self.attribute_name)
def __set_name__(self, owner, name):
self.attribute_name = name + "_hidden_part"
class User:
field = Descriptor()
u = User()
print(u.field)
u.field = 1
print(u.field)
del u.field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment