【问题标题】:Running file in IDLE window from command line directly直接从命令行在 IDLE 窗口中运行文件
【发布时间】:2019-03-07 19:50:14
【问题描述】:
所以我可以在 (Windows) cmd 中使用以下命令打开一个文件以使用 IDLE 进行编辑:
python -m idlelib main.py
# not sure if there's a better way to do that
但是,有没有办法直接运行文件并让它的输出打开一个新的 IDLE 窗口(或切换到当前打开的 IDLE 窗口)?
【问题讨论】:
标签:
python
python-3.x
cmd
python-idle
【解决方案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