Python equivalent of _tempnam?

Richard richardd at hmgcc.gov.uk
Wed Apr 2 11:58:51 CEST 2003


Hi,

I am writing an application which produces file output. Files are outputted
to a directory and I want to ensure that if an output filename is given that
already exists in that directory a number is affixed to the filename to
ensure that the existing file is not appended to or overwritten. i.e.
output_0.txt, then output_1.txt etc...

I have been told that a way of doing this in C is by using _tempnam( ).
However I want to write this in Python, so is there an equivalent function?
My application will only be executed occasionally so I am unable to keep an
internal record of file numbering. I assume that I need to find the highest
number file (if exists) in the directory and then increment that by one
before creating the new file.

Any ideas?

Cheers

Richard






More information about the Python-list mailing list