[英]How to start a shell from a python script
我想運行一個腳本,該腳本進行一些設置,然后在該環境中打開一個 shell。 所以而不是然后做
$ python
>>> # do some setup
>>> # start doing what I really came here to do
我想要做
$ python my_script.py
>>> # start doing what I really came here to do
使用-i
參數運行腳本:
python -i my_script.py
這將執行my_script.py
並在之后進入交互式 shell。
你可以做這樣的事情
import code
variables = {"test": True}
shell = code.InteractiveConsole(variables)
shell.interact()
現在它將打開python shell,您可以直接訪問測試變量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.