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
630
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
63
The `max` function
eloy
0
58
The Command Line Interface
eloy
2
480
Other Decks in Technology
See All in Technology
Node-REDのFunctionノードでMCPサーバーの実装を試してみた / Node-RED × MCP 勉強会 vol.1
you
PRO
0
120
なぜ私はいま、ここにいるのか? #もがく中堅デザイナー #プロダクトデザイナー
bengo4com
0
480
低レイヤを知りたいPHPerのためのCコンパイラ作成入門 完全版 / Building a C Compiler for PHPers Who Want to Dive into Low-Level Programming - Expanded
tomzoh
4
3.3k
生成AI時代の開発組織・技術・プロセス 〜 ログラスの挑戦と考察 〜
itohiro73
1
280
【TiDB GAME DAY 2025】Shadowverse: Worlds Beyond にみる TiDB 活用術
cygames
0
1.1k
2年でここまで成長!AWSで育てたAI Slack botの軌跡
iwamot
PRO
4
760
Leveraging Open-Source Tools for Creating 3D Tiles in the Urban Environment
simboss
PRO
0
100
PHPでWebブラウザのレンダリングエンジンを実装する
dip_tech
PRO
0
210
Kotlin Coroutine Mechanisms: A Surprisingly Deep Rabbithole
amanda_hinchman
2
100
Microsoft Build 2025 技術/製品動向 for Microsoft Startup Tech Community
torumakabe
2
300
Javaで作る RAGを活用した Q&Aアプリケーション
recruitengineers
PRO
1
120
AIの最新技術&テーマをつまんで紹介&フリートークするシリーズ #1 量子機械学習の入門
tkhresk
0
140
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
How STYLIGHT went responsive
nonsquared
100
5.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Gamification - CAS2011
davidbonilla
81
5.3k
How GitHub (no longer) Works
holman
314
140k
Docker and Python
trallard
44
3.4k
Rails Girls Zürich Keynote
gr2m
94
14k
4 Signs Your Business is Dying
shpigford
184
22k
Side Projects
sachag
455
42k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Embracing the Ebb and Flow
colly
86
4.7k
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