python标准库os中的方法startfile_如何使用Python 打开exel等各种文件或者应用,就用:os.startfile...

python虽然可以有库打开excel文件,但这个问题不是讨论这个。

而是如何通过python 直接打开各种各样的文件或者应用。

有几种方式,os.system,subprocess.Popen,os.startfile.

先看看各个介绍:

os.system:

system(...)

system(command) -> exit_status

Execute the command (a string) in a subshell.

subprocess.Popen:

class Popen(__builtin__.object)

|  Methods defined here:

|

|  __del__(self, _maxint=2147483647, _active=[])

|

|  __init__(self, args, bufsize=0, executable=None, stdin=None, stdout=None, st

derr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, un

iversal_newlines=False, startupinfo=None, creationflags=0)

|      Create new Popen instance.

os.startfile:

startfile(...)

startfile(filepath [, operation]) - Start a file with its associated

application.

When "operation" is not specified or "open", this acts like

double-clicking the file in Explorer, or giving the file name as an

argument to the DOS "start" command: the file is opened with whatever

application (if any) its extension is associated.

When another "operation" is given, it specifies what should be done with

the file.  A typical operation is "print".

startfile returns as soon as the associated application is launched.

There is no option to wait for the application to close, and no way

to retrieve the application's exit status.

The filepath is relative to the current directory.  If you want to use

an absolute path, make sure the first character is not a slash ("/");

the underlying Win32 ShellExecute function doesn't work if it is.

看到这块,已经很明确了,就是她了:os.startfile

如果只有路径,相当于在浏览器双击这个文件!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值