gpt4 book ai didi

python - 从 python 脚本启动 python IDLE

转载 作者:行者123 更新时间:2023-12-05 04:18:43 25 4
gpt4 key购买 nike

我怎样才能以某种方式从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com