start default application for read a pdf from python

Angelo Ballabio angbal at
Wed Sep 9 21:59:22 CEST 2009

Thenks for this suggestion, at the end I find this solution

import os
#then where I decide to show the file in the default application I put this

	#file_name the name I construct with path and all necessary
	#recor contain all the data of one record end the 4th position
	#the name of the file
	#for example
	file_name = os.path.join('document',str(record[3]) + ".pdf")
	#the joun function make the separator from ducoment to the file
	#name relative to operatin system (windows '\') , (unix '/')

	#then where I call the default program
	if == "nt":
		os.filestart("%s" % nome_file)
	elif == "posix":
		os.system("/usr/bin/xdg-open %s" % nome_file)

Other nice solution is

	import webbrowser

The difference is in unix sistem, the first call the default program for 
read the file of type, in this case pdf, this meens okular, acroread, or 
whatever, the second open the konqueror in kde desktop, in windows the 
function os.filestart call the default application for thet type of file

interesting discussion about this I find in :

very thenks to all

Albert Hopkins ha scritto:
> The (most) portable way to do so in Linux (not necessarily Unix) is to
> use the xdg-open command.  Ex, 
>     subprocess.Popen(['xdg-open', 'my-document.pdf'])

More information about the Python-list mailing list