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]
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]:
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
>> 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
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
> 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
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
> 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
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
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
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
11 matches
Mail list logo