[英]Python and terminal: keep python environment after the file has been executed
I have to run a Python file from the Windows terminal (Windows PowerShell).我必须从 Windows 终端 (Windows PowerShell) 运行 Python 文件。 I want that after the file has been executed (
python foo.py
), python keeps open with the variables defined in the file.我希望在文件执行后(
python foo.py
),python 保持打开状态,并使用文件中定义的变量。
If it is unclear what I want, I want the same behavior as IDLE, after the file has been executed, you can write code in the IDLE command line and the variables defined in the file are stored in current session.如果不清楚我想要什么,我想要与 IDLE 相同的行为,文件执行后,您可以在 IDLE 命令行中编写代码,文件中定义的变量存储在当前会话中。
I need this for Windows now, but I might also need this for Ubuntu.我现在需要这个用于 Windows,但我可能也需要这个用于 Ubuntu。
Apply the -i
parameter as follows:按如下方式应用
-i
参数:
python -i foo.py
(Transcribed from python
help): (转录自
python
帮助):
python -h
usage: python [option]... [-c cmd | -m mod | file | -] [arg]... Options (and corresponding environment variables): … -i: inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x …
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.