简体   繁体   English

Python和终端:文件执行后保持python环境

[英]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.

相关问题 恢复脚本后退出python脚本到终端 - exiting a python script to terminal after the script has been restsrted python 测试在收到结果后继续运行 - python tests keep running after result has been received python:连续读取文件,即使它已经被logrotated - python: read file continuously, even after it has been logrotated 如何在文件循环后删除文件-Python - How to remove a file after it has been loop through-Python 检查在python中打开后是否删除了打开的文件 - Check if an open file has been deleted after open in python cmd警告:python解释器在conda环境中,但是环境没有被激活 - cmd warning: python interpreter is in a conda environment, but the environment has not been activated 警告“此 Python 解释器处于 conda 环境中,但该环境尚未激活” - Warning "This Python interpreter is in a conda environment, but the environment has not been activated" 这个Python解释器在conda环境下,但是环境还没有激活 - This Python interpreter is in a conda environment, but the environment has not been activated Python Anaconda解释器在conda环境下,但是环境没有激活 - Python Anaconda interpreter is in a conda environment, but the environment has not been activated Python解释器在Conda环境中,但是该环境没有被激活 - Python interpreter is in a Conda environment, but the environment has not been activated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM