从命令行直接在IDLE窗口中运行文件

时间:2018-10-02 16:23:14

标签: python python-3.x cmd python-idle

因此,我可以在(Windows)IDLE中使用以下命令打开文件进行cmd的编辑:

python -m idlelib main.py
# not sure if there's a better way to do that

但是,有没有一种方法可以运行该文件,并让其输出直接打开一个新的IDLE窗口(如果打开,则切换到当前窗口)?

1 个答案:

答案 0 :(得分:1)

是的,请使用帮助部分中所述的-r选项:

USAGE: 
   idle  [-deins] [-t title] [file]*
   idle  [-dns] [-t title] (-c cmd | -r file) [arg]*
   idle  [-dns] [-t title] - [arg]*

-h         print this help message and exit
-n         run IDLE without a subprocess (DEPRECATED,
           see Help/IDLE Help for details)

The following options will override the IDLE 'settings' configuration:

-e         open an edit window
-i         open a shell window

The following options imply -i and will open a shell:

-c cmd     run the command in a shell, or
-r file    run script from file

-d         enable the debugger
-s         run $IDLESTARTUP or $PYTHONSTARTUP before anything else
-t title   set title of shell window
....

所以,您会这样做:

python -m idlelib -r main.py