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
50
The `max` function
eloy
0
42
The Command Line Interface
eloy
2
470
Other Decks in Technology
See All in Technology
サーバー間 GraphQL と webmock-graphql の話 / server-to-server graphql and webmock-graphql
qsona
2
190
EMとして2023年度に頑張ったこと / What we did well in FY2023 as a EM
pauli
1
170
エンジニア候補者向け資料2024.04.24.pdf
macloud
0
3.3k
JAWS-UG Bedrock Claude Night
yamahiro
3
610
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
1
250
今年のRubyKaigiはProfiler Year🤘
osyoyu
0
170
長期間TiDBを使ってきた話 @ 私たちはなぜNewSQLを使うのかTiDB選定5社が語る選定理由と活用LT / Experiences with TiDB Over Time
chibiegg
2
900
いつか使うかも貯金してたらめちゃめちゃ機能が増えてた話
riyaamemiya
0
290
Google Cloud Next '24でブログを10本書いた方法と勉強会を沸かせた方法
yasumuusan
0
300
自己改善からチームを動かす! 「セルフエンジニアリングマネージャー」のすゝめ
shoota
6
780
Azure Container Apps + Bicep 〜 こんな感じで運用しています
kaz29
2
480
20240418_Google ColabにLLMが搭載されたようなのでPython x データ分析の勉強方法を考えてみる
doradora09
0
140
Featured
See All Featured
Atom: Resistance is Futile
akmur
259
25k
The Brand Is Dead. Long Live the Brand.
mthomps
49
29k
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
Teambox: Starting and Learning
jrom
128
8.4k
A Philosophy of Restraint
colly
197
16k
Practical Orchestrator
shlominoach
182
9.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
Automating Front-end Workflow
addyosmani
1356
200k
Typedesign – Prime Four
hannesfritz
36
2.1k
Documentation Writing (for coders)
carmenintech
60
3.9k
How STYLIGHT went responsive
nonsquared
92
4.8k
Optimising Largest Contentful Paint
csswizardry
8
2.4k
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