代码之家  ›  专栏  ›  技术社区  ›  N Chauhan Nathan Hinchey

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

  •  1
  • N Chauhan Nathan Hinchey  · 技术社区  · 7 年前

    所以我可以打开一个文件来编辑 IDLE 在(Windows)中使用以下命令 cmd

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

    但是,有没有一种方法可以直接运行这个文件并让它的输出打开一个新的空闲窗口(或者切换到当前的空闲窗口,如果有的话)?

    1 回复  |  直到 7 年前
        1
  •  3
  •   N Chauhan Nathan Hinchey    7 年前

    是的,使用 -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