Is there a way to make python become interactive in the middle of a script?

后端 未结 6 1035
执笔经年
执笔经年 2021-02-01 07:03

I\'d like to do something like:

do lots of stuff to prepare a good environement
become_interactive
#wait for Ctrl-D
automatically clean up

Is i

6条回答
  •  渐次进展
    2021-02-01 07:59

    Not exactly the thing you want but python -i will start interactive prompt after executing the script.

    -i : inspect interactively after running script, (also PYTHONINSPECT=x) and force prompts, even if stdin does not appear to be a terminal

    $ python -i your-script.py
    Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
    ...
    >>> 
    

提交回复
热议问题