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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Eloy Zuniga Jr.
June 19, 2012
Technology
8
640
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
78
The `max` function
eloy
0
62
The Command Line Interface
eloy
2
490
Other Decks in Technology
See All in Technology
Phase08_クイックウィン実装
overflowinc
0
2k
Astro Islandsの 内部実装を 「日本で一番わかりやすく」 ざっくり解説!
knj
0
290
「通るまでRe-run」から卒業!落ちないテストを書く勘所
asumikam
2
770
モジュラモノリス導入から4年間の総括:アーキテクチャと組織の相互作用について / Architecture and Organizational Interaction
nazonohito51
8
4.3k
AIエージェント×GitHubで実現するQAナレッジの資産化と業務活用 / QA Knowledge as Assets with AI Agents & GitHub
tknw_hitsuji
0
260
AI時代のIssue駆動開発のススメ
moongift
PRO
0
270
AIエージェント勉強会第3回 エージェンティックAIの時代がやってきた
ymiya55
0
140
QA組織のAI戦略とAIテスト設計システムAITASの実践
sansantech
PRO
1
200
VSCode中心だった自分がターミナル沼に入門した話
sanogemaru
0
770
Phase11_戦略的AI経営
overflowinc
0
1.7k
GitHub Advanced Security × Defender for Cloudで開発とSecOpsのサイロを超える: コードとクラウドをつなぐ、開発プラットフォームのセキュリティ
yuriemori
1
100
脳が溶けた話 / Melted Brain
keisuke69
1
1.1k
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.8k
Designing for humans not robots
tammielis
254
26k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
230
Visualization
eitanlees
150
17k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.5k
A Tale of Four Properties
chriscoyier
163
24k
Writing Fast Ruby
sferik
630
63k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
440
Discover your Explorer Soul
emna__ayadi
2
1.1k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
130
Optimizing for Happiness
mojombo
378
71k
The Cult of Friendly URLs
andyhume
79
6.8k
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