This snippet defines a context
autofilename() to create an existing temporary file with a new name in python. Unlike the methods in the
tempfile module, it only gives a filename which exists within a 'with' block, instead of an open file. This is useful for example when a program needs to pass a new filename to a function which does not accept a file object argument. As with the tempfile module, there should be no race condition between processes on the temporary file creation.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.