python - 从 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。

https://stackoverflow.com/questions/10664461/

相关文章:

django - 保存前更改表单实例 Django

wordpress - 如何在 Wordpress 中回显 100% 的 the_post?

xcode - 如何在 Xcode 分析和存档构建中设置 DEBUG 和 NDEBUG 宏?

authentication - 你将如何实现 "view site as a different

sql - 在所有列中搜索并找到一个字符串值

qt - 如何确保 QWidget 在屏幕外?

hibernate - 如何定义两个抽象类之间的 ManyToOne 关系

git - 为什么提交后文件保留在索引中?

oracle - 使用 sqlloader 将 clob 列添加到 Oracle 数据库

asp.net - 读取已在 ASP.NET httpmodule 中设置的经典 ASP 中的服务器