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
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.1k
Debugging Apollo iOS with Apollo Client Developer Tools
manicmaniac
0
80
Other Decks in Programming
See All in Programming
5分で問診!Composer セキュリティ健康診断
codmoninc
0
340
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
110
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
150
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
550
共通化で考えるべきは、実装より公開する型だった
codeegg
0
250
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.4k
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
510
霧の中の代数的エフェクト
funnyycat
1
400
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
790
Featured
See All Featured
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Prompt Engineering for Job Search
mfonobong
0
380
ラッコキーワード サービス紹介資料
rakko
1
3.9M
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
390
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
Building Applications with DynamoDB
mza
96
7.1k
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!