Upgrade to Pro — share decks privately, control downloads, hide ads and more …

`shell invocation` in Python 2

`shell invocation` in Python 2

Presentation for Quipper Alumni Meetup held in 2019.

Avatar for Ryosuke Ito

Ryosuke Ito

December 16, 2019
Tweet

More Decks by Ryosuke Ito

Other Decks in Programming

Transcript

  1. Ryosuke Ito • iOS software engineer • Working for Quipper

    Ltd. since Apr. 2019 • Loves Python @manicmaniac
  2. 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`
  3. 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, '('), ]) ...
  4. Backquotes in Python 3 >>> `date` File "<stdin>", line 1

    `date` ^ SyntaxError: invalid syntax