- 1 year ago
How to know where is windows installed with Python?
Comment
1 / 1
To determine the installation location of Windows using Python, you can retrieve the value of the SYSTEMROOT
environment variable. Here's an example:
pythonimport os
windows_installation_path = os.environ['SYSTEMROOT']
print("Windows Installation Path:", windows_installation_path)
In this example, os.environ
is a dictionary containing the environment variables of the current system. By accessing the value of the SYSTEMROOT
key, you can retrieve the installation path of Windows.
The SYSTEMROOT
environment variable typically points to the Windows directory where the core system files are stored. This location is often C:\Windows
, but it can vary depending on the system configuration.
Executing the above code will output the installation path of Windows.