2010-09-01 77 views

回答

4

OSX:

os.system('open "%s"' % foldername) 

的Windows:

os.startfile(foldername) 

的Unix:

os.system('xdg-open "%s"' % foldername) 

組合:

import os 

systems = { 
    'nt': os.startfile, 
    'posix': lambda foldername: os.system('xdg-open "%s"' % foldername) 
    'os2': lambda foldername: os.system('open "%s"' % foldername) 
    } 

systems.get(os.name, os.startfile)(foldername) 
+0

是在U nix兼容Linux(愚蠢的問題,我知道),它是否與所有發行版兼容? – skeggse 2010-09-01 16:01:50

+0

Linux是一個類Unix系統。是的,如果他們默認安裝了xdg-open(所有現代發行版),它與所有發行版都兼容。 xdg-open是打開文件夾最兼容的方式,因爲沒有通用的方法來執行此操作,因爲對於每個桌面管理員都需要不同的方法。 – leoluk 2010-09-01 16:11:13