Skip to content

Instantly share code, notes, and snippets.

@linzino7
Created September 25, 2017 14:42
Show Gist options
  • Save linzino7/91ecb95ba360229d8e048dbdb1ce591d to your computer and use it in GitHub Desktop.
Save linzino7/91ecb95ba360229d8e048dbdb1ce591d to your computer and use it in GitHub Desktop.
Python Decorator Pattern Example
# -*- 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