0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

#python のインタラクティブモードで事前に走らせるスクリプトを指定して Ruby の binding.pry みたいに途中から操作してみる ( python -i ) ( + #django shell の例も )

Last updated at Posted at 2019-05-06
  • python -i で インタラクティブモードで起動し、なおかつ事前に特定のスクリプトを走らせられる模様
  • IPython とかかいろいろと面倒な場合もあるので、シェルを立ち上げてからファイルを読むこむ方式でやってみる。
-i     : inspect interactively after running script; forces a prompt even

import file example

import re
print('OK!')
alices = re.findall(r'Alice', 'AliceAliceAlice')

python の場合

$ python -i tmp/import.py
OK!
>>> alices
['Alice', 'Alice', 'Alice']

django の場合

  • 途中から exec で読み込めば良さげ
  • 他の方法は未発見
$ ./manage.py shell
In [1]: exec(open('./tmp/import.py').read())
OK!
In [2]: alices
Out[2]: ['Alice', 'Alice', 'Alice']

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?