Python 打开系统文件管理器¶ 概要: 使用Python标准库打开Explorer和Finder 创建时间: 2022.09.25 19:09:34 更新时间: 2023.10.26 00:27:24 打开Windows的Explorer¶ 对于 Windows系统,Python 3.7+的 os 标准库模块提供了十分方便的接口,极其友好 Python1 2 3import os os.startfile('C:\Users\lzwang') 打开macOS的Finder¶ 对于 *unix 系统,需要调用系统的 open 命令 Python1 2 3import subprocess subprocess.call(['open', '/Users/lzwang']) 如果只需要定位到某个文件夹,那么加上 -R 参数 Python1 2 3import subprocess subprocess.call(['open', '-R', '/Users/lzwang']) 参考¶ python - PyQt - How to open a directory folder? - Stack Overflow python - AttributeError: 'module' object has no attribute 'startfile' - Stack Overflow