Skip to content

Instantly share code, notes, and snippets.

@StephenFordham
Last active February 12, 2022 18:35
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 StephenFordham/6f0fcfdaaf1916628f2a210f3b81ac72 to your computer and use it in GitHub Desktop.
Save StephenFordham/6f0fcfdaaf1916628f2a210f3b81ac72 to your computer and use it in GitHub Desktop.
Example_2_using_classes.py
class StrAttrValidation(object):
def __init__(self):
self._dict = dict()
def __set__(self, instance, value):
self._dict[instance] = value.title()
def __get__(self, instance, value):
return self._dict[instance]
class Employees(object):
name = StrAttrValidation()
location = StrAttrValidation()
def __init__(self, name, location):
self.name = name
self.location = location
emp1 = Employees('stephen', 'bournemouth')
print(emp1.name)
print(emp1.location)
#Terminal Output
Stephen
Bournemouth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment