Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.tempnam() method

Python os.tempnam() method

Python File methods Python OS file/directory methods


Overview

The os.tempnam() method returns a unique pathname for creating a temporary file.

Syntax

The syntax of the **tempnam()** method is as follows:



os.tempnam(dir, prefix)

Parameters

Return Value

This method returns a unique path.

Example

The following example demonstrates the use of the tempnam() method:

Example

#!/usr/bin/python

-- coding: UTF-8 --

import

os

,

sys

A file with the prefix runoob

tmpfn

=

os

.

tempnam

(

'/tmp/runoob'

,

'runoob'

)

print

"This is a unique path:"

print

tmpfn

The output of the above program is:



This is a unique path:

/tmp/runoob/runoobIbAco8

Python File methods Python OS file/directory methods