Created
September 25, 2017 14:42
-
-
Save linzino7/91ecb95ba360229d8e048dbdb1ce591d to your computer and use it in GitHub Desktop.
Python Decorator Pattern Example
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Sep 25 21:57:40 2017 | |
@author: linzino | |
""" | |
#python Decorator Pattern | |
def print_my_name(name): | |
return name | |
def my_name(): | |
return "Hans" | |
def tow_name(): | |
return "tow" | |
print_my_name(my_name) | |
print_my_name(tow_name) | |
print(my_name()) | |
print(tow_name()) | |
#---------same--------- | |
def print_my_name(name): | |
return name # return 傳進來的 function | |
@print_my_name | |
def my_name(): | |
return "Hans" | |
@print_my_name | |
def tow_name(): | |
return "tow" | |
print(my_name()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment