Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Python Decorators
Search
Eloy Zuniga Jr.
June 19, 2012
Technology
8
620
Python Decorators
A basic understanding of Python Decorators.
Eloy Zuniga Jr.
June 19, 2012
Tweet
Share
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The Filter Function
eloy
0
58
The `max` function
eloy
0
52
The Command Line Interface
eloy
2
470
Other Decks in Technology
See All in Technology
Larkご案内資料
customercloud
PRO
0
650
エンジニアのためのドキュメント力基礎講座〜構造化思考から始めよう〜(2025/02/15jbug広島#15発表資料)
yasuoyasuo
17
6.8k
急成長する企業で作った、エンジニアが輝ける制度/ 20250214 Rinto Ikenoue
shift_evolve
3
1.3k
2/18/25: Java meets AI: Build LLM-Powered Apps with LangChain4j
edeandrea
PRO
0
120
全文検索+セマンティックランカー+LLMの自然文検索サ−ビスで得られた知見
segavvy
2
110
抽象化をするということ - 具体と抽象の往復を身につける / Abstraction and concretization
soudai
16
6.8k
N=1から解き明かすAWS ソリューションアーキテクトの魅力
kiiwami
0
130
OpenID BizDay#17 KYC WG活動報告(法人) / 20250219-BizDay17-KYC-legalidentity
oidfj
0
250
Building Products in the LLM Era
ymatsuwitter
10
5.5k
データマネジメントのトレードオフに立ち向かう
ikkimiyazaki
6
980
Oracle Cloud Infrastructure:2025年2月度サービス・アップデート
oracle4engineer
PRO
1
210
Goで作って学ぶWebSocket
ryuichi1208
1
880
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
How to Ace a Technical Interview
jacobian
276
23k
Docker and Python
trallard
44
3.3k
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Speed Design
sergeychernyshev
27
790
Transcript
Decorators What are they? How to explain them. Tuesday, June
19, 12
Tuesday, June 19, 12
Basic definition Decorator is a function that takes a function
as a parameter and returns a function Tuesday, June 19, 12
Basic definition Decorator is a function that takes a function
as a parameter and returns a function Is a function. Takes a function. Returns a function Tuesday, June 19, 12
func = func_hugger(func) Illustration Tuesday, June 19, 12
def in_bed(func): def f(): return ‘%s In bed.’ % func()
return f Change output Tuesday, June 19, 12
def in_bed(func): def f(): if f.in_pool: return ‘%s In pool.’
% func() return ‘%s In bed.’ % func() f.in_pool = False return f Add attributes Tuesday, June 19, 12
def in_bed(func): def f(*args, **kwargs): if args or kwargs: raise
Exception(‘wat?’) return ‘%s In bed.’ % func() return f Validate Tuesday, June 19, 12
Tuesday, June 19, 12
Basic definition Is a function. Takes a function. Returns a
function Tuesday, June 19, 12
Syntactic Sugar Annotation Syntax Tuesday, June 19, 12
Syntactic Sugar Annotation Syntax @func Tuesday, June 19, 12
def luke_quote(): return “I’m Luke SkyWalker, I’m here to rescue
you.” Decorate Tuesday, June 19, 12
def luke_quote(): return “I’m Luke SkyWalker, I’m here to rescue
you.” Decorate @in_bed Tuesday, June 19, 12
def luke_quote(): return “I’m Luke SkyWalker, I’m here to rescue
you.” Decorate @in_bed @no_inbreeding Tuesday, June 19, 12
def luke_quote(): return “I’m Luke SkyWalker, I’m here to rescue
you.” Decorate @in_bed(with=”lightsaber”) @in_bed Tuesday, June 19, 12
Tuesday, June 19, 12
@eloy Tuesday, June 19, 12