python - 从 python 脚本启动 python IDLE

标签 python python-idle

我怎样才能以某种方式从 python 脚本启动 Python-IDLE,以便之前在脚本中声明的所有变量和函数在 IDLE 中都是已知的?

最佳答案

您可以使用以下命令从命令行运行 IDLE:

idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...

-c command  run this command
-d          enable debugger
-e          edit mode; arguments are files to be edited
-s          run $IDLESTARTUP or $PYTHONSTARTUP first
-t title    set title of shell window

还有:

Upon startup with the -s option, IDLE will execute the file referenced by the environment variables IDLESTARTUP or PYTHONSTARTUP. Idle first checks for IDLESTARTUP; if IDLESTARTUP is present the file referenced is run. If IDLESTARTUP is not present, Idle checks for PYTHONSTARTUP. Files referenced by these environment variables are convenient places to store functions that are used frequently from the Idle shell, or for executing import statements to import common modules. (From the docs: http://docs.python.org/library/idle.html)

因此,您可以将 $IDLESTARTUP 或 $PYTHONSTARTUP 设置为包含您要声明的变量的 python 文件,它们将在 IDLE 启动时可用。

您可以通过使用 os.system 命令(或 subprocess.Popen)运行上面的命令,以这种方式从 Python 脚本启动 IDLE。

关于python - 从 python 脚本启动 python IDLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10664461/

相关文章:

python - 如何运行 Python 项目?

python - 从命令行启动 Python IDLE 以编辑脚本

python - 如何使用代理进行 pip 安装

python - 安装后无法运行 Radian(改进的 R 控制台)

python - 如何使用 python 检索 mysqlDB 中存储为 BLOB 的文件

python - Sphinx meth 角色不创建链接

python - 如何使用 Python API 修改 Azure Block Blob 中的特定 block ?

python - 如何在 IDLE 中为 Python 函数指定自定义工具提示描述

tkinter - Python IDE IDLE 如何在光标位置的文本小部件顶部显示自动完成列表?

python - 当我从IDLE运行GASP时,为什么它不起作用?