Search code examples
pythonmacossubprocesspopen

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


Solution

  • Use open (1) command.

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