3

The content of the file or the picture should show up in a new window.

Rakshit Pai
  • 291
  • 2
  • 15
dj macelroy
  • 31
  • 1
  • 2
  • I'm assuming that you want to open a file with its default application. For example, given a .bmp, open Paint with that file. Is this the case? If so, see http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python – Wesley May 02 '11 at 17:21

3 Answers3

4

That will depend a lot on your operating system, since there are different programs on different systems to view images, etc. But one trick you might use is

import webbrowser
webbrowser.open(THE_FILE)

That should open up your default web browser pointed to the file, which will display images, and might do what you want for certain types of files.

Mu Mind
  • 10,935
  • 4
  • 38
  • 69
  • 1
    Actually, it looks like on my system this opens the image viewer directly for images and PDF viewer for PDFs, so it might be even better for what you wanted than I thought. – Mu Mind May 02 '11 at 17:29
2

you could try

os.system("fspot picture.jpeg")

But, obviously, I'm assuming you're using fspot to view images, and that might only work in linux.

Check out the documentation for os.

-EDIT- Mu Mind's solution works pretty well in Ubuntu Karmic. Not sure what it will do on a windows machine.

MikeVaughan
  • 1,441
  • 1
  • 11
  • 18
1

you can use

os.system("start "+"anyfile.txt")

assuming you have windows. This basically opens the file in it's extension (For example if you had a .txt it would open in notepad.)

Jester
  • 59
  • 2