[Tutor] tempfile and webbrowser

yves yegrix at free.fr
Sun Sep 3 22:54:05 CEST 2006


Kent Johnson a écrit :

> The problem is that the file is never actually written because you omit 
> the close. But when you do close the temp file, it is deleted. Try using 
> a.flush() instead of a.close(), that will force the file to be written. 
> Alternately use tempfile.mkstemp() which lets you close the file and 
> delete it when you are done with it.

Thank you,
this works:
********
import tempfile
import webbrowser

a = tempfile.mkstemp('.html')
f= open(a[1],'w')
f.write("<html>Test</html>")
f.close()
webbrowser.open(f.name)
*********
-- 
Yves Egrix


More information about the Tutor mailing list