我刚刚开始学习Python。当我在Windows上执行一个python脚本文件时,输出窗口出现但立即消失。我需要它停留在那里,这样我就可以分析我的输出。我怎么才能让它一直开着?
当前回答
一个非常迟的回答,但我创建了一个名为pythonbat.bat的Windows批处理文件,其中包含以下内容:
python.exe %1
@echo off
echo.
pause
然后指定pythonbat.bat作为.py文件的默认处理程序。
现在,当我在文件资源管理器中双击一个.py文件时,它会打开一个新的控制台窗口,运行Python脚本,然后暂停(保持打开),直到我按下任何键……
无需更改任何Python脚本。
我仍然可以打开一个控制台窗口,并指定python myscript.py,如果我想…
(我刚刚注意到@maurizio已经发布了这个确切的答案)
其他回答
我也遇到过类似的问题。在notepad++中,我曾经使用命令:C:\Python27\python.exe "$(FULL_CURRENT_PATH)"在代码终止后立即关闭cmd窗口。 现在我使用cmd /k c:\Python27\python.exe "$(FULL_CURRENT_PATH)"它保持cmd窗口打开。
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
在python 2中,你可以使用:raw_input()
>>print("Hello World!")
>>raw_input('Waiting a key...')
在python 3中,你可以使用:input()
>>print("Hello world!")
>>input('Waiting a key...')
你也可以用时间。sleep(time)
>>import time
>>print("The program will close in 5 seconds")
>>time.sleep(5)
一个非常迟的回答,但我创建了一个名为pythonbat.bat的Windows批处理文件,其中包含以下内容:
python.exe %1
@echo off
echo.
pause
然后指定pythonbat.bat作为.py文件的默认处理程序。
现在,当我在文件资源管理器中双击一个.py文件时,它会打开一个新的控制台窗口,运行Python脚本,然后暂停(保持打开),直到我按下任何键……
无需更改任何Python脚本。
我仍然可以打开一个控制台窗口,并指定python myscript.py,如果我想…
(我刚刚注意到@maurizio已经发布了这个确切的答案)
你可以打开PowerShell,输入“python”。 导入Python之后,您可以从您最喜欢的文本编辑器中复制粘贴源代码来运行代码。
窗户关不上。
推荐文章
- 证书验证失败:无法获得本地颁发者证书
- 当使用pip3安装包时,“Python中的ssl模块不可用”
- 无法切换Python与pyenv
- Python if not == vs if !=
- 如何从scikit-learn决策树中提取决策规则?
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 将旋转的xtick标签与各自的xtick对齐
- 为什么元组可以包含可变项?
- 如何合并字典的字典?
- 如何创建类属性?
- 不区分大小写的“in”
- 在Python中获取迭代器中的元素个数
- 解析日期字符串并更改格式
- 我如何找到哪个程序正在使用端口80在Windows?
- 使用try和。Python中的if