如何在python中的mac osx上打开文件

问题描述 投票:0回答:1

我试图使用eclipse在python中打开Mac上的文件。

FileName = "/Users/fis/Desktop/installation_guide.txt"
ss = subprocess.Popen(FileName, shell=True)
ss.communicate()

还有os.popen(FileName)。但文件没有打开。这些代码在windows中运行良好。但是,我不知道mac的问题是什么。我想打开一个文件,就像双击Windows打开文件一样,而不是像阅读文件内容和在控制台中打印一样。文件出现在Mac上的桌面位置

python macos subprocess popen
1个回答
3
投票

使用open (1)命令。

import subprocess
FileName = "/Users/fis/Desktop/installation_guide.txt"
subprocess.call(['open', FileName])
© www.soinside.com 2019 - 2024. All rights reserved.