1

I am creating a code which allows a user to scan an barcode, resulting in the correct file in the explorer they need to open on the computer. A BIG problem I have recently run in to: the files only open properly when they are opened through the application they run on.

My question would then be, is it possible to create a script which mimics opening a file through an application? Similar to being in excel and clicking File -> Open... If this is possible, what would be the first steps in order to make it happen?

rpanai
  • 12,515
  • 2
  • 42
  • 64
JFP323
  • 11
  • 1
  • If the application has registered its extension properly, then you can just invoke the file as if it were a program. Example, `os.system("abcdef.xlsx")` will open Excel on that file. (I should caution -- that's Windows only.) – Tim Roberts Apr 15 '21 at 00:03
  • On Ubuntu-based systems, I believe `xdg-open` will work (also through `os.system`). Not sure about other Linuxes; it's probably different on each. – Silvio Mayolo Apr 15 '21 at 00:11
  • By "opened through the application", do you mean you can not double click and open the file, nor right click and select the app you want to use to open it? – Ranoiaetep Apr 15 '21 at 00:27

3 Answers3

0

What you're talking about is unfortunately not possible with python. But you can open the files with their default application through a subprocess. Try following the answer here.

Kerfuffle
  • 11
  • 1
0

You can do this using by pyqt library. More information for pyqt: What is pyqt

For the Open File option on pyqt: More about Qfile dialog

Mert
  • 71
  • 3
0

If you are on Windows, you might be able to use COM automation via win32com to have the program open the file if the program supports it. I know this works with the Office programs.

Dan D.
  • 73,243
  • 15
  • 104
  • 123