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

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

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

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

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

最佳答案

是的,使用帮助部分中描述的-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

关于python - 直接从命令行在 IDLE 窗口中运行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52612511/

相关文章:

python - 仅在特定时间合并两个数据帧

python-3.x - 图像和标签在 TFRecord 中不对应

python - 如何 pickle 和去 pickle

cmd - 如何从 youtube-dl 转换脚本

batch-file - CMD 批处理不喜欢错误重定向

python - 想检测拼图的边角部分,但找不到每 block 的4个角

python - 使用圆的定积分计算 pi

php - 在哪里可以获得英语的 UTF-8 字符的完整列表?

python-3.x - 删除 Candlestick_ohlc 图表中两个日期之间的空白

batch-file - 如果存在计划任务