Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a file with the standard application?

Tags:

My application prints a PDF to a temporary file. How can I open that file with the default application in Python?

I need a solution for

  • Windows
  • Linux (Ubuntu with Xfce if there's nothing more general.)

Related

  • Open document with default application in Python
like image 780
Georg Schölly Avatar asked Nov 05 '09 10:11

Georg Schölly


2 Answers

os.startfile is only available for windows for now, but xdg-open will be available on any unix client running X.

if sys.platform == 'linux2':     subprocess.call(["xdg-open", file]) else:     os.startfile(file) 
like image 63
Nicolas Dumazet Avatar answered Nov 26 '22 13:11

Nicolas Dumazet


on windows it works with os.system('start <myFile>'). On Mac (I know you didn't ask...) it's os.system('open <myFile>')

like image 25
Kai Huppmann Avatar answered Nov 26 '22 13:11

Kai Huppmann