我刚刚开始学习Python。当我在Windows上执行一个python脚本文件时,输出窗口出现但立即消失。我需要它停留在那里,这样我就可以分析我的输出。我怎么才能让它一直开着?
当前回答
Go here and download and install Notepad++ Go here and download and install Python 2.7 not 3. Start, Run Powershell. Enter the following. [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User") Close Powershell and reopen it. Make a directory for your programs. mkdir scripts Open that directory cd scripts In Notepad++, in a new file type: print "hello world" Save the file as hello.py Go back to powershell and make sure you are in the right directory by typing dir. You should see your file hello.py there. At the Powershell prompt type: python hello.py
其他回答
我也遇到过类似的问题。在notepad++中,我曾经使用命令:C:\Python27\python.exe "$(FULL_CURRENT_PATH)"在代码终止后立即关闭cmd窗口。 现在我使用cmd /k c:\Python27\python.exe "$(FULL_CURRENT_PATH)"它保持cmd窗口打开。
从已经打开的cmd窗口或启动脚本 在Python 2中,在脚本的末尾添加如下内容:
raw_input("Press enter to exit;")
或者,在Python 3中:
input("Press enter to exit;")
Go here and download and install Notepad++ Go here and download and install Python 2.7 not 3. Start, Run Powershell. Enter the following. [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User") Close Powershell and reopen it. Make a directory for your programs. mkdir scripts Open that directory cd scripts In Notepad++, in a new file type: print "hello world" Save the file as hello.py Go back to powershell and make sure you are in the right directory by typing dir. You should see your file hello.py there. At the Powershell prompt type: python hello.py
如果你想保持cmd-window打开并且在运行文件目录下,这在Windows 10下是有效的:
cmd /k cd /d $(CURRENT_DIRECTORY) && python $(FULL_CURRENT_PATH)
你可以直接写
input()
在代码的末尾
因此,当你运行你的脚本时,它会等待你输入一些东西
{ENTER for example}
推荐文章
- 使用Conda进行批量包更新
- Ipython笔记本清除单元格输出代码
- ImportError: numpy.core.multiarray导入失败
- 有办法在Python中使用PhantomJS吗?
- 如何在Python中将if/else压缩成一行?
- 如何在Python 3中使用pip。Python 2.x
- 如何让IntelliJ识别常见的Python模块?
- Django:“projects”vs“apps”
- 如何列出导入的模块?
- 转换Python程序到C/ c++代码?
- 如何从gmtime()的时间+日期输出中获得自epoch以来的秒数?
- 在python模块文档字符串中放入什么?
- 我如何在Django中过滤一个DateTimeField的日期?
- 在Python中用索引迭代列表
- -e,——editable选项在pip install中什么时候有用?