Python的:如何打开Windows资源管理器的文件夹(Python的3.6.2的Windows 10)

问题描述 投票:3回答:3

如果我保存,我想在一个字符串名为finalpath这看起来是这样打开的路径:“./2.8电影/英语/虎胆龙威系列”

那么怎样在Windows资源管理器?(视窗10)(Python的3.6.2)打开

P.S我知道很多人都问过这个问题,但我没有发现他们明确的。请尽快答复。

windows python-3.x operating-system windows-10 windows-explorer
3个回答
13
投票

我发现了一个简单的方法。

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

7
投票

其他选择

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

或单独的操作系统

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

或子

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

要么

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

2
投票

跨平台:

import webbrowser


path = 'C:/Users'

webbrowser.open('file:///' + path)
© www.soinside.com 2019 - 2024. All rights reserved.