1.在python中好像有mailcap这个模块。
2.http://pypi.python.org/pypi /desktop这里还有一个专门统一桌面操作的python库
3.还有这样也行
os.spawnvp(os.P_WAIT, "run-mailcap", ["run-mailcap", name])
4.好像这样也行
import os
if os.name == 'posix':
def startfile(name):
os.system('run-mailcap "%s"' % name)
os.startfile = startfile
不过只是针对debian系列的linux
5.
http://groups.google.com/group/python-cn/browse_thread/thread/becb84da60efdc91
#5 is the best solution for launching program associated with file.
Test code:
#!/usr/bin/env python
#coding = utf-8
import os, sys
cmd = None
if os.name=='posix':
#cmd = "xdg-open '%s' &"
cmd = os.popen('''which op xdg-open exo-open gnome-open kfmclient open | head -n1 | sed "s/$/ '%s' /&/; s/kfmclient/kfmclient exec/"''').read()
elif os.name=='nt':
cmd = 'start %s'
def opendoc(filename):
os.popen(cmd%filename)
opendoc(sys.argv[1])
2.http://pypi.python.org/pypi
3.还有这样也行
os.spawnvp(os.P_WAIT, "run-mailcap", ["run-mailcap", name])
4.好像这样也行
import os
if os.name == 'posix':
def startfile(name):
os.system('run-mailcap "%s"' % name)
os.startfile = startfile
不过只是针对debian系列的linux
5.
http://groups.google.com/group/python-cn/browse_thread/thread/becb84da60efdc91
import os
if os.name=='posix':
#cmd = "xdg-open '%s' &"
cmd = os.popen('''which op xdg-open exo-open gnome-open kfmclient
open | head -n1 | sed "s/$/ '%s' /&/; s/kfmclient/kfmclient exec/"
''').read()
elif os.name=='nt':
cmd = 'start %s'
def opendoc(filename):
'用操作系统默认程序打开文件'
os.popen(cmd%filename)
#5 is the best solution for launching program associated with file.
Test code:
#!/usr/bin/env python
#coding = utf-8
import os, sys
cmd = None
if os.name=='posix':
#cmd = "xdg-open '%s' &"
cmd = os.popen('''which op xdg-open exo-open gnome-open kfmclient open | head -n1 | sed "s/$/ '%s' /&/; s/kfmclient/kfmclient exec/"''').read()
elif os.name=='nt':
cmd = 'start %s'
def opendoc(filename):
os.popen(cmd%filename)
opendoc(sys.argv[1])
本文介绍了一种在不同操作系统上使用默认程序打开文件的方法。通过Python脚本实现,覆盖了从Ubuntu、MAC OS X、Windows XP、Vista到OpenSolaris等桌面操作系统。
3723

被折叠的 条评论
为什么被折叠?



