-
-
Save gevasiliou/76be5e0e422919d0775f04e618863251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SetterNGetter(): | |
def __init__(self, *args, **kwargs): | |
self.my_age = kwargs['age'] | |
self.my_name = kwargs['name'] | |
@property | |
def my_age(self): | |
return self.my_age | |
@my_age.setter | |
def my_age(self, value): | |
self.my_age = value | |
@my_age.deleter | |
def my_age(self): | |
del(self.my_age) | |
@property | |
def my_name(self): | |
return self.my_name | |
@my_name.setter | |
def my_name(self, value): | |
self.my_name = value | |
@my_name.deleter | |
def my_name(self): | |
del(self.my_name) | |
def check_age(my_func): | |
def check(*args, **kwargs): | |
print_young(kwargs['age'], kwargs['name']) if kwargs['age'] < 40 else print_old(kwargs['age'], kwargs['name']) | |
def print_young(age, name): | |
print '\nHi, %s\n %i is young' % (name, age) | |
def print_old(age, name): | |
if age >= 100: | |
print '\nHi, %s\n At %i years of age you should be dead' % (name, age) | |
else: | |
print '\nHi, %s\n %i is old' % (name, age) | |
return check | |
@check_age | |
def do_age_check(*args, **kwargs): | |
return args, kwargs | |
if __name__ == "__main__": | |
go_get = SetterNGetter(age=[23], name=['Dick']) | |
go_get.my_age.append(24) | |
go_get.my_name.append('Fred') | |
go_get.my_age.append(100) | |
go_get.my_name.append('Bob') | |
go_get.my_age.append(74) | |
go_get.my_name.append('Tom') | |
for i, a in enumerate(go_get.my_age): | |
do_age_check(age=a, name=go_get.my_name[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment