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
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
CloudFrontのHost Header転送設定でパケットの中身はどう変わるのか?
nagisa53
1
220
TUNA Camp 2026 京都Stage ヒューリスティックアルゴリズム入門
terryu16
0
620
FASTでAIエージェントを作りまくろう!
yukiogawa
4
160
「通るまでRe-run」から卒業!落ちないテストを書く勘所
asumikam
3
850
Change Calendarで今はOK?を仕組みにする
tommy0124
1
130
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
17k
RGBに陥らないために -プロダクトの価値を届けるまで-
righttouch
PRO
0
130
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
4
1.3k
CREがSLOを握ると 何が変わるのか
nekomaho
0
240
「AIエージェントで変わる開発プロセス―レビューボトルネックからの脱却」
lycorptech_jp
PRO
0
180
Even G2 クイックスタートガイド(日本語版)
vrshinobi1
0
120
OpenClawでPM業務を自動化
knishioka
1
320
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
My Coaching Mixtape
mlcsv
0
87
Designing for Performance
lara
611
70k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
200
Marketing to machines
jonoalderson
1
5.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Designing for humans not robots
tammielis
254
26k
Embracing the Ebb and Flow
colly
88
5k
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