Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Python Decorators
Search
Eloy Zuniga Jr.
June 19, 2012
Technology
650
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Python Decorators
A basic understanding of Python Decorators.
Eloy Zuniga Jr.
June 19, 2012
Transcript
18 slides
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
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The Filter Function
eloy
0
120
The `max` function
eloy
0
73
The Command Line Interface
eloy
2
530
Other Decks in Technology
See All in Technology
そのイメージ、どのCIが作った? Artifact Attestationsで来歴を固定する / Which CI system created that image? Pinning provenance with Artifact Attestations
chmikata
0
270
AWS DevOps Agentの構造から読み解く運用 AI エージェントの設計原則/aws-devops-agent-design-principles
tomoki10
0
280
HTTP通信に使おうとすると実はめんどくさいfile_get_contents
maguroalternative
0
260
OCI Artifact による自動運転タクシーに向けた OTA 基盤の構築
biwashi
1
300
現地速報! Microsoft Ignite アップデートレポート
kasada
1
460
Webメール開発を大幅に変えたJMAPというゲームチェンジャー
tascript
5
2k
パスワードのない鍵で、 データを手元に置く
ginjihayashi
0
400
専門家に使ってもらうAIプロダクトをつくる - 病院の医事課向けDPCコーディング支援システムの設計と評価
hagino3000
4
1k
お風呂場をサーバルームにしよう
yusuke427
0
400
社内アプリ基盤「Quartz」による、 非エンジニアとAIに本番デプロイを 任せても壊れないプラットフォームの設計
staka121
PRO
1
230
kubellの最新データ分析環境
kubell_hr
2
270
MCPでネットワーク障害調査を自動化する前に直すべき3つのこと
yama3133
1
670
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
3
12k
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
30 Presentation Tips
portentint
PRO
1
480
Evolving SEO for Evolving Search Engines
ryanjones
0
370
So, you think you're a good person
axbom
PRO
2
2.3k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
390
New Earth Scene 8
popppiees
5
2.9k