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
76
The `max` function
eloy
0
60
The Command Line Interface
eloy
2
490
Other Decks in Technology
See All in Technology
Data Hubグループ 紹介資料
sansan33
PRO
0
2.7k
ClickHouseはどのように大規模データを活用したAIエージェントを全社展開しているのか
mikimatsumoto
0
200
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
210
データ民主化のための LLM 活用状況と課題紹介(IVRy の場合)
wxyzzz
2
680
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
130
OCI Database Management サービス詳細
oracle4engineer
PRO
1
7.4k
インフラエンジニア必見!Kubernetesを用いたクラウドネイティブ設計ポイント大全
daitak
0
330
AIと新時代を切り拓く。これからのSREとメルカリIBISの挑戦
0gm
0
800
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
200
今日から始めるAmazon Bedrock AgentCore
har1101
4
400
Amazon S3 Vectorsを使って資格勉強用AIエージェントを構築してみた
usanchuu
3
440
会社紹介資料 / Sansan Company Profile
sansan33
PRO
15
400k
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Everyday Curiosity
cassininazir
0
130
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Side Projects
sachag
455
43k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
The Invisible Side of Design
smashingmag
302
51k
Crafting Experiences
bethany
1
48
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.5k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
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