Last active
November 4, 2015 13:25
-
-
Save dskecse/037de9c5cacba8f0f557 to your computer and use it in GitHub Desktop.
Decorators in Python
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
def honorific(klass): | |
class HonorificClass(klass): | |
def full_name(self): | |
return 'Dr. ' + super(HonorificClass, self).full_name() | |
return HonorificClass | |
@honorific | |
class Person(object): | |
def __init__(self, first, last): | |
self.first = first | |
self.last = last | |
def full_name(self): | |
return ' '.join([self.first, self.last]) | |
name = Person('Emmet', 'Brown').full_name() | |
print 'full name: {0}'.format(name) # full name: Dr. Emmet Brown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment