File assocations inconsistent behaviour with Windows 10

After updating Python, my file associations somehow got messed up and I have been trying to get them to behave. Here’s my test program PyArgs.py:

import sys, os 
print ("Arguments count  : " + str (len (sys.argv)))
print ("Arguments        : " + str (sys.argv))
print ("Python version   : " + sys.version) ;
print ("Python executable: " + sys.executable) ;
print ("Script path      : " + os.path.realpath(__file__))
exit

and there is a console dump that illustrates my problem:

C:\TOOLS>"C:\Users\Raymond\AppData\Local\Programs\Python\Python38\python.exe" pyargs.py 1 2 3
Arguments count  : 4
Arguments        : ['pyargs.py', '1', '2', '3']
Python version   : 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]
Python executable: C:\Users\Raymond\AppData\Local\Programs\Python\Python38\python.exe
Script path      : C:\TOOLS\pyargs.py

C:\TOOLS>pyargs.py 1 2 3
Arguments count  : 1                                                     <=========================== ??
Arguments        : ['C:\\TOOLS\\pyargs.py']                              <=========================== ??
Python version   : 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]
Python executable: C:\Users\Raymond\AppData\Local\Programs\Python\Python38\python.exe
Script path      : C:\TOOLS\pyargs.py

C:\TOOLS>assoc .py
.py=Python.File

C:\TOOLS>ftype Python.File
Python.File="C:\Users\Raymond\AppData\Local\Programs\Python\Python38\python.exe" "%L" %*

So if I invoke the script explicitly with the path to python.exe, the script sees the parameters, but if I invoke it via the .py file association it doesn’t. What am I missing?

I have tagged the question as python but I’m not convinced that is anything to do with python, just my incomplete configuration of the file associations.

If I go to the file association settings I see:

enter image description here

The second Python icon looks like it might be associated with command-line operation. Anyway, I changed the .py file association to that icon and the behaviour hasn’t changed.

Answer

Attribution
Source : Link , Question Author : rossmcm , Answer Author : Community

Leave a Comment