This value is stored in the registery at the location _HKEY_LOCAL_MACHINE\SOFTWARE\Classes. For example, the value of the key Python.File at this location is Python File.
The first step is to get the key name linked with the human readable name of the file. That key is the value of the key name as the extension name located at the same path.
Then, thanks to this value, get the name of the file by its key name.
To sum up with an example:
\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.py gives Python.File
\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File gives Python File
In python, to get values in the registery, you can use winreg package.
from typing import Tuple
from winreg import HKEYType, ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
class ExtensionQuery:
def __init__(self):
self.base: str = r"SOFTWARE\Classes"
self.reg: HKEYType = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
def _get_value_from_class(self, class_str: str) -> str:
path: str = fr"{self.base}\{class_str}"
key: HKEYType = OpenKey(self.reg, path)
value_tuple: Tuple[str, int] = QueryValueEx(key, "")
return value_tuple[0]
def get_application_name(self, ext: str) -> str:
return self._get_value_from_class(self._get_value_from_class(ext))
query = ExtensionQuery()
print(query.get_application_name(".py"))