Python: How to open a folder on Windows Explorer(Python 3.6.2, Windows 10) Python: How to open a folder on Windows Explorer(Python 3.6.2, Windows 10) windows windows

Python: How to open a folder on Windows Explorer(Python 3.6.2, Windows 10)


I found a simple method.

import ospath = "C:/Users"path = os.path.realpath(path)os.startfile(path)


Other alternatives

import webbrowser, ospath="C:/Users"webbrowser.open(os.path.realpath(path))

or with os alone

import osos.system(f'start {os.path.realpath(path)}')

or subprocess

import subprocess,ossubprocess.Popen(f'explorer {os.path.realpath(path)}')

or

subprocess.run(['explorer', os.path.realpath(path)])


Cross platform:

import webbrowserpath = 'C:/Users'webbrowser.open('file:///' + path)