1

How do I open a file from python? Not using the open() function and read or write, I mean simulate a user double clicking on the file. So if I open file1.jpg I want it to open using the default image program.

Thanks

1
  • 2
    u should import os, and use some appropriate tool... like xdg-open... i.e. _____ os.system(dxg-open) Commented Sep 17, 2014 at 22:15

2 Answers 2

3

in linux you can use xdg-open like bellow:

from subprocess import call
call(['xdg-open','filename'])
Sign up to request clarification or add additional context in comments.

Comments

0

On windows, you get this behavior if you execute through the win32 shell. An easy way to do that is with the subprocess module:

import subprocess as subp
subp.call('file1.jpg', shell=True)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.