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
`shell invocation` in Python 2
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ryosuke Ito
December 16, 2019
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
`shell invocation` in Python 2
Presentation for Quipper Alumni Meetup held in 2019.
Ryosuke Ito
December 16, 2019
More Decks by Ryosuke Ito
See All by Ryosuke Ito
React Native 卒業後の「スタディサプリ」の進路
manicmaniac
2
2.5k
iOS app meets GraphQL
manicmaniac
0
4.2k
Debugging Apollo iOS with Apollo Client Developer Tools
manicmaniac
0
81
Other Decks in Programming
See All in Programming
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
420
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
200
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
130
信頼性の目標を誰も求めてない
shubox
0
240
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
530
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
260
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
1
2k
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
390
バグを直したら useEffect が消えた
colorful12
3
770
Introducing Stack Pull Request in GitHub
kkamegawa
0
110
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
170
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
480
Test your architecture with Archunit
thirion
2
2.4k
Code Reviewing Like a Champion
maltzj
528
40k
Building an army of robots
kneath
306
46k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
490
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
490
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Bash Introduction
62gerente
615
220k
Product Roadmaps are Hard
iamctodd
55
12k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
220
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
180
Transcript
`shell invocation` in Python 2 @manicmaniac
Ryosuke Ito • iOS software engineer • Working for Quipper
Ltd. since Apr. 2019 • Loves Python @manicmaniac
Python 2
EOL of Python 2 2020-01-01 00:00:00 Only 15 days left!
Shell invocation
In Ruby puts `date`
In Perl print `date`
In Python 2.7 import subprocess print subprocess.check_output([‘date’]),
In Python <= 2.6 import subprocess process = subprocess.Popen(['date'], stdout=subprocess.PIPE),
stdout, _ = process.communicate() print stdout,
How can I `date`?
Backquotes in Python 2 `date` == repr(date) == date.__repr__()
Naive implementation import subprocess class date(object): def __repr__(self): return subprocess.check_output(‘date’)
date = date() print `date`
Using meta class import subprocess def register_command(name): def __repr__(self): return
subprocess.check_output( self.__class__.__name__ ) globals()[name] = type( name, (object,), dict(__repr__=__repr__) )() register_command('date') print `date`
But how about other commands?
import backquotes print `date`
None
How it works?
Preprocessing import tokenize def preprocess(filename, readline): for token in tokenize.generate_tokens(readline):
... if inside_backquotes: tokens.extend([ (tokenize.NAME, 'backquotes'), (tokenize.OP, '.'), (tokenize.NAME, 'shell'), (tokenize.OP, '('), ]) ...
At Runtime frame = inspect.currentframe().f_back while frame.f_code.co_filename.startswith('<frozen importlib'): frame =
frame.f_back execfile(source, frame.f_globals, frame.f_locals)
print `date`
Limitations • Doesn’t work on REPL • Doesn’t work on
Python 3 • Really buggy
Backquotes in Python 3 >>> `date` File "<stdin>", line 1
`date` ^ SyntaxError: invalid syntax
Don’t use backquotes
R.I.P Python 2 Thank you for listening!