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
リテール金融(キャッシュレス・ネット銀行・ネット証券)の競争環境と経済圏
8maki
0
1.7k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
37k
IaCからAWSに入門した初心者が CloudFormationを通して考えた「AWS操作」の使い分け
maimyyym
2
530
一生覚えておきたい「システム開発=コミュニケーション」〜初めての実務案件振り返りLT〜
maimyyym
3
380
VSCodeの拡張機能を作っている話
ebarakazuhiro
1
830
.NET Profiler in 2024.
kkamegawa
2
2k
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
35k
Google Cloud Next '24 Recap(Cloud Run/k8s)
mokocm
0
360
地理空間データ可視化・解析・活用ソリューション Pacific Spatial Solutions (PSS)
pacificspatialsolutions
0
350
Gemini, Google's Large Language Model
glaforge
0
110
BPStudyの200回を中心にIT業界を振り返る。そしてこれから
haru860
3
420
ルーターでプレゼンする
puhitaku
1
3.4k
Featured
See All Featured
From Idea to $5000 a Month in 5 Months
shpigford
378
45k
Debugging Ruby Performance
tmm1
70
11k
Mobile First: as difficult as doing things right
swwweet
217
8.6k
Gamification - CAS2011
davidbonilla
77
4.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
261
12k
YesSQL, Process and Tooling at Scale
rocio
165
13k
Product Roadmaps are Hard
iamctodd
45
9.8k
Building Effective Engineering Teams - LeadDev
addyosmani
32
1.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
117
18k
The Pragmatic Product Professional
lauravandoore
26
5.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
14
1.5k
For a Future-Friendly Web
brad_frost
172
9k
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