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)
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
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.
Confirm that the
ProgId
value in Explorer'sUserChoice
key for .py files has been changed toPython.File
. For example:Finally verify that the
Python.File
command template is what you expect it to be: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 eitherHKCU\Software\Classes
orHKLM\Software\Classes
instead of the combinedHKCR
view.