tempfile problem on win98 
Author Message
 tempfile problem on win98

Hi,

I'm using the tempfile module in python 1.5.2 and it keeps giving me
duplicate filenames.

It's being called only once each time the script runs, (small cgi
messageboard) with this is the code related to the tempfile:

 import tempfile
 tempfile.tempdir=SOME_DIRECTORY
 tempfile.template=None
 id=tempfile.mktemp()

shouldn't this give me a unique value for id every time? I initially
had it running without the tempfile.template being assigned None, but
when I noticed the duplicate filenames, so I thought I'd try that.

Currently I'm making it recompute tempfile names until it has one that
does not already exist, but why does this happen?once I get a lot of
messages in the system I don't want to be possibly iterating through
the whole lot checking their names (unfortunately I don't have
permissions or the space to use a proper database)

thanks for any help,

Steven



Mon, 08 Sep 2003 21:25:32 GMT  
 tempfile problem on win98
The mktemp routine guarantees to return a name unique in the target
directory.  Are you sure you're using fully qualified path names throughout
when subsequently discovering duplicate files?

Emile van Sebille


Quote:
> Hi,

> I'm using the tempfile module in Python 1.5.2 and it keeps giving me
> duplicate filenames.

> It's being called only once each time the script runs, (small cgi
> messageboard) with this is the code related to the tempfile:

>  import tempfile
>  tempfile.tempdir=SOME_DIRECTORY
>  tempfile.template=None
>  id=tempfile.mktemp()

> shouldn't this give me a unique value for id every time? I initially
> had it running without the tempfile.template being assigned None, but
> when I noticed the duplicate filenames, so I thought I'd try that.

> Currently I'm making it recompute tempfile names until it has one that
> does not already exist, but why does this happen?once I get a lot of
> messages in the system I don't want to be possibly iterating through
> the whole lot checking their names (unfortunately I don't have
> permissions or the space to use a proper database)

> thanks for any help,

> Steven



Mon, 08 Sep 2003 21:54:55 GMT  
 tempfile problem on win98
I just notice as well that the routine doesn't in fact create the file, so
that a delay in using the name, or accessing mktemp from another process
could also result in duplicates.

Emile



Quote:
> The mktemp routine guarantees to return a name unique in the target
> directory.  Are you sure you're using fully qualified path names
throughout
> when subsequently discovering duplicate files?

> Emile van Sebille




Mon, 08 Sep 2003 21:57:50 GMT  
 tempfile problem on win98



Quote:
> The mktemp routine guarantees to return a name unique in the target
> directory.  Are you sure you're using fully qualified path names
throughout
> when subsequently discovering duplicate files?

> Emile van Sebille


ugh, I feel dumb, thats exactly the problem Emile, the file was
getting an extension added and so it wasn't actually unique, is there
a way to have a suffix included in the calculation of the filename
instead of the prefix?

thanks for opening my eyes to the glaringly obvious :-)

Steven



Tue, 09 Sep 2003 22:43:39 GMT  
 tempfile problem on win98
Steven,

You can pass mktemp a suffix parameter, ala:

 id=tempfile.mktemp(suffix='spam')

HTH,
--

Emile van Sebille

---------

Quote:



> > The mktemp routine guarantees to return a name unique in the target
> > directory.  Are you sure you're using fully qualified path names
> throughout
> > when subsequently discovering duplicate files?

> > Emile van Sebille

> ugh, I feel dumb, thats exactly the problem Emile, the file was
> getting an extension added and so it wasn't actually unique, is there
> a way to have a suffix included in the calculation of the filename
> instead of the prefix?

> thanks for opening my eyes to the glaringly obvious :-)

> Steven



Tue, 09 Sep 2003 23:17:46 GMT  
 tempfile problem on win98

Quote:

> is there a way to have a suffix included in the calculation of the
> filename instead of the prefix?

http://www.python.org/doc/current/lib/module-tempfile.html

    mktemp([suffix])

    Return a unique temporary filename. This is an absolute
    pathname of a file that does not exist at the time the call
    is made. No two calls will return the same filename.

    suffix, if provided, is used as the last part of the generated
    file name. This can be used to provide a filename extension
    or other identifying information that may be useful on some
    platforms.

worth trying...

Cheers /F



Wed, 10 Sep 2003 00:24:23 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. tempfile.mktemp no longer obeys tempfile.tempdir?

2. problem with using Tempfile

3. tempfile problem CosmoPlayer2.1 & NSC4.5

4. Tempfile.py destructor problem (python 1.4)

5. Tempfile warning message: "output left in <tempfile>"?

6. Win98 Problem with deployed DLL

7. printing problems running dos 2.1 apps under win98

8. HELP!! Win98 Environment Problem

9. CFD in Win98 SHARE problem??

10. C5/Win98/Nt4.0 - Illegal Operation Problem

11. Win98 4.10.98 Problem

12. DLL - Win98/XP problems

 

 
Powered by phpBB® Forum Software