sqlite and TemporaryFile under Windows

Paul McNett p at ulmcnett.com
Tue Oct 16 12:28:48 EDT 2007


Matthieu Brucher wrote:
>      > If this is the way of using sqlite, it is still cumbersome as a
>     lot of
>      > other classes that work on files can work on file-like (and isn't
>     it the
>      > whole point of Python ;) ?
> 
>     I don't think that sqlite can work on streams, or on file-like objects.
> 
> 
> 
> Obviously it cannot, but what are the reason it can't ?

I have no idea.


>     You could just save it as tempfile.mktemp(). I think the utility of this
>     function in this case outweighs the possibility that your routine will
>     coincidentally overwrite another file of the same name within the same
>     fraction of a second. The warning is dire, but when you think about it
>     in context it doesn't seem that bloody likely that there will be a
>     problem. ;)
> 
> 
> Well, I could, but in this case I have to delete the file myself, which 
> the whole point of the use of TemporaryFile.

Go with the flow dude! Unless you want to solve the issue by delving in 
to the source for pysqlite yourself so that it can work on file-like 
object, the extra os.unlink call doesn't seem to be a big deal.

Also, you are downloading the file off the Internet somewhere anyway. 
Either you work with that stream without creating a file (which we've 
already discovered isn't possible) or you save it to a file. Sure, it 
would be nice to use TemporaryFile(), but it shouldn't be a showstopper 
to use mktemp() an unlink() instead.


-- 
pkm ~ http://paulmcnett.com



More information about the Python-list mailing list