In Windows 10, is it possible to make a file with a specific extension run with a given Python script? For example, I have .pickle files saved, and I wrote a simple Python script to print them out. I would like to double click on the .pickle file and have the Python script that prints it run.
I was able to create a context menu entry that successfully did this. For example, this simple Python script named
import pickle import sys filename = sys.argv print(filename) var = pickle.load(open(filename, 'rb')) print(type(var)) if type(var) == list: print(len(var)) for ii, value in enumerate(var): print(ii, value) elif type(var) == dict: print(len(var)) for key, val in var.items(): print(key, val, sep="t") elif type(var) == set: print(len(var)) for ii in var: print(ii) else: print(var) input("Press enter")
And the registry key at
ComputerHKEY_CLASSES_ROOTSystemFileAssociations.pickleshellViewcommand with a (Default) REG_SZ Data value of
"C:Program FilesPythonPython38python.exe" "C:ScriptsPythonview_pickle_file.py" "%1":
which prints out the pickle file perfectly.
But this is a context menu entry. I want to double click the .pickle file to make this happen. How would I do that? Is it possible? Or is the context menu entry as close as I will ever get?