Re: [Tutor] tempfile and webbrowser

2006-09-10 Thread Kent Johnson
yves wrote: > Kent Johnson a écrit : > > Hello, > >> Try it like this, using os.fdopen() to convert the low-level file handle >> from mkstemp() to a Python file object: >> >> In [21]: fd, fname = tempfile.mkstemp() >> >> In [22]: f = os.fdopen(fd, 'w') >> >> In [23]: f.write('foo') >> >> In [24]

Re: [Tutor] tempfile and webbrowser

2006-09-10 Thread yves
Kent Johnson a écrit : Hello, > Try it like this, using os.fdopen() to convert the low-level file handle > from mkstemp() to a Python file object: > > In [21]: fd, fname = tempfile.mkstemp() > > In [22]: f = os.fdopen(fd, 'w') > > In [23]: f.write('foo') > > In [24]: f.close() > > In [25]:

Re: [Tutor] tempfile and webbrowser

2006-09-08 Thread Kent Johnson
Alan Gauld wrote: >>> Use os.remove() instead. >> os.remove() and os.unlink() are identical according to the docs; if >> you look at posix_module.c you can see this is true - they both map >> to posix_unlink(). >> >> Kent > > Maybe so, but os.remove() works on my XP box... :-) > > I didn't try

Re: [Tutor] tempfile and webbrowser

2006-09-08 Thread Alan Gauld
>> Use os.remove() instead. > > os.remove() and os.unlink() are identical according to the docs; if > you look at posix_module.c you can see this is true - they both map > to posix_unlink(). > > Kent Maybe so, but os.remove() works on my XP box... :-) I didn't try unlink since the OP said it di

Re: [Tutor] tempfile and webbrowser

2006-09-08 Thread Kent Johnson
Alan Gauld wrote: >> The file deletion (os.unlink(f.name)) does not work on Windows (it >> works on Ubuntu with Python 2.4, though). >> >> So, is there a way to get this os.unlink(f.name) to work on Windows? > > Use os.remove() instead. os.remove() and os.unlink() are identical according to the

Re: [Tutor] tempfile and webbrowser

2006-09-08 Thread Alan Gauld
> The file deletion (os.unlink(f.name)) does not work on Windows (it > works on Ubuntu with Python 2.4, though). > > So, is there a way to get this os.unlink(f.name) to work on Windows? Use os.remove() instead. Alan G. ___ Tutor maillist - Tutor@py

Re: [Tutor] tempfile and webbrowser

2006-09-07 Thread yves
Hello, Here is another problem: Considering this programm: import os, tempfile a = tempfile.mkstemp() f= open(a[1],'w') f.write("foo") f.close() print f.name # here some code to do some things with f os.unlink(f.name) The output is: Python 2.3.3 (#51, Dec 18 2003, 20

Re: [Tutor] tempfile and webbrowser

2006-09-03 Thread Alan Gauld
> This program works: > ** > import webbrowser > a = open('test.htm','wb') Any particular feason to open the file in binary mode? That can sometimes cause odd things to happen. > a.write("Test") > webbrowser.open(a.name) > a.close() The close should come before the browser reads the fi

Re: [Tutor] tempfile and webbrowser

2006-09-03 Thread yves
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 y

Re: [Tutor] tempfile and webbrowser

2006-09-03 Thread Kent Johnson
yves wrote: > Hello tutors, > > This programm works: > ** > import webbrowser > a = open('test.htm','wb') > a.write("Test") > webbrowser.open(a.name) > a.close() > *** > but I would like to avoid the risk of overwriting an already existing > "test.htm" file, so I try to use the modu

[Tutor] tempfile and webbrowser

2006-09-03 Thread yves
Hello tutors, This programm works: ** import webbrowser a = open('test.htm','wb') a.write("Test") webbrowser.open(a.name) a.close() *** but I would like to avoid the risk of overwriting an already existing "test.htm" file, so I try to use the module tempfile: *** import tem