0

I am trying to use Python to open a file for visual browsing, i.e. as if one double clicked a file to view it. I have tried numerous searches but because the words are very similar with doing file I/O I could not come across the appropriate information.

I think this is a very simple question / answer and I apologize if the answer was right in front of my nose.

Ideally it would just be a call on a given file path and Python would know the appropriate application to pair in case it was an extension like .pdf.

user3898238
  • 957
  • 3
  • 11
  • 25
  • You mean use Python to invoke Adobe Reader to open a pdf file, for instance? – Stephen Lin Aug 01 '14 at 09:29
  • This Question is a duplicate. Check: [http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python][1] [1]: http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python – Christoph Hegemann Aug 01 '14 at 09:33
  • http://stackoverflow.com/questions/3277503/python-read-file-line-by-line-into-array – Mher Aug 01 '14 at 09:34
  • Many apologies for duplicating this question. I think I lacked the proper vocabulary for describing this--all of what I pulled up before was File I/O. – user3898238 Aug 02 '14 at 01:00

2 Answers2

0

On Windows you can use os.startfile().

os.startfile("C:\\Users\\your\\file.pdf")
TheDarkTurtle
  • 413
  • 1
  • 3
  • 12
0
  1. os.startfile()

  2. os.system() but the parameters passed varies according to the OS

    Windows: Start fileName Mac: open fileName Linux: oowriter fileName : gnome-open fileName : kde-open fileName etc...

Example:

fileName="file.pdf" //Path to the file
1. os.startfile(fileName)
2. os.system("start %s")%fileName
Yogeesh Seralathan
  • 1,396
  • 4
  • 15
  • 22