一、利用explorer.exe
import os
# 利用explorer.exe执行
start_directory = r'D:\testdir'
os.system("explorer.exe %s" % start_directory)
二、用os.startfile
import os
# opens explorer at C:\ drive,just work for windows
start_directory = r'D:\testdir'
os.startfile(start_directory)
三、利用subprocess
import os
import subprocess
# 利用subprocess
def startfile(filename):
try:
os.startfile(filename)
except:
subprocess.Popen(['xdg-open', filename])
start_directory = r'D:\testdir'
startfile(start_directory)