简体   繁体   中英

How to open a file on mac osx in python

I am trying to open a file on mac in python using eclipse.

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

And also os.popen(FileName) . But file is not opening. These codes work fine in windows. But, I don't know whats the problem with mac. I want to open a file just like double-clicking on windows to open a file and not like reading the content of file and printing in console. File is present on Desktop location on mac

Use open (1) command.

import subprocess
FileName = "/Users/fis/Desktop/installation_guide.txt"
subprocess.call(['open', FileName])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM