为什么控制台会自动最小化? [英] Why is the console minimized automatically?

查看:295
本文介绍了为什么控制台会自动最小化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手。今天,我在控制台中运行Python脚本时发现了一个问题。当我在cmd中运行脚本时,它会自动最小化。此外,如果我仅打开cmd来执行.py文件,则它会同时打开最小化的文件。最后,什么都没有写入控制台。有人知道为什么吗?

I am a new to Python. Today I found a problem when running Python scripts in the console. When I run a script in cmd, it gets minimized automatically. Moreover, if I only open cmd to execute the .py file, it opens the file minimized at the same time. In the end, nothing is written to the console. Does anyone know why?

如果是代码本身引起了问题,我将其粘贴在下面:

In case it is the code itself that causes the problem, I've pasted it below:

# -*- coding: utf-8 -*-
from functools import reduce    
def fn(x,y):
        return x*10+y
def char2num(s):
        return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[s]
t=reduce(fn,map(char2num,'123456'))
print(t)






根据以下命令,.py文件关联当前由Notepad ++处理。


According to the following command, the .py file association is currently handled by Notepad++.

>reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice

    Hash    REG_SZ     rHDUu4DAyAc=
    ProgId    REG_SZ    Applications\Notepad++.exe


推荐答案

行为异常,因为打开.py文件目前由Notepad ++文本编辑器处理,而不是由py.exe或python.exe处理。要解决此问题,请先打开控制面板中的默认程序对话框。选择将文件类型或协议与程序关联的选项。滚动到 .py,然后双击它。选择上面带有Python徽标的 Python条目,如果有多个,则最好选择上面带有火箭的条目。单击确定后,描述现在应该是 Python文件,并且在顶部应该有一个带有 Python软件基金会的Python图标。

It's misbehaving because opening .py files is currently handled by the Notepad++ text editor instead of either py.exe or python.exe. To fix this, begin by opening the Default Programs dialog in the Control Panel. Select the option to associate a file type or protocol with a program. Scroll to ".py" and double click on it. Select the "Python" entry with the Python logo on it, and preferably the one with a rocket on it if there's more than one. After clicking ok, the description should now be "Python File", and up at the top it should have the Python icon with "Python Software Foundation" beside it.

确认已将.py文件的Explorer的 UserChoice 密钥中的 ProgId 值更改为 Python。文件。例如:

Confirm that the ProgId value in Explorer's UserChoice key for .py files has been changed to Python.File. For example:

>reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice /v ProgId

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice
    ProgId    REG_SZ    Python.File

最后确认 Python .file 命令模板就是您期望的模板:

Finally verify that the Python.File command template is what you expect it to be:

>reg query HKCR\Python.File\shell\open\command

HKEY_CLASSES_ROOT\Python.File\shell\open\command
    (Default)    REG_SZ    "C:\Windows\py.exe" "%L" %*

,我为所有用户安装了py启动器,这是Python 3安装的默认设置。模板中的%L %1 是.py脚本的完全限定路径, %* 用于命令行参数。如果您必须解决此问题,那么在regedit中最简单。最好您在 HKCU\Software\Classes HKLM\Software\Classes 而不是合并后的 HKCR 视图。

In my case, I have the py launcher installed for all users, which is the default setup for a Python 3 installation. "%L" or "%1" in the template is the fully-qualified path for the .py script, and %* is for the command-line parameters. If you have to fix this, it will be easiest to do it in regedit. Preferably you should edit the underlying software classes in either HKCU\Software\Classes or HKLM\Software\Classes instead of the combined HKCR view.

这篇关于为什么控制台会自动最小化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆