相当于Windows中双击的Python子进程模块 [英] Python subprocess module equivalent for double-click in Windows

查看:87
本文介绍了相当于Windows中双击的Python子进程模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用subprocess模块打开文件,就像在资源管理器中双击该文件一样.我该怎么办?

I want to open a file using the subprocess module as though the file was double-clicked in Explorer. How do I do that?

我尝试了以下行:

subprocess.call("C:/myfile.csv", shell=True)

抛出错误:

命令的语法是 不正确.
'C:\'不被识别为 内部或外部命令, 可操作的程序或批处理文件.

The syntax of the command is incorrect.
'C:\' is not recognized as an internal or external command, operable program or batch file.

如何使用subprocess模拟双击?基本上,我想在Excel 2007中打开CSV文件.

How do I emulate a double-click using subprocess? Basically I want to open a CSV file in Excel 2007.

推荐答案

os.startfile(r'C:\myfile.csv')

(仅Win32.对于Mac,使用'open filename';在Linux/freedesktop-in-general的'xdg-open filename'上运行一个进程.)

(Win32 only. For Mac, run a process with 'open filename'; on Linux/freedesktop-in-general, 'xdg-open filename'.)

这篇关于相当于Windows中双击的Python子进程模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆