Python os.tempnam() Method

Python File(文件) 方法Python OS File/Directory Methods


Overview

The os.tempnam() method is used to return a unique path name for creating a temporary file.

Syntax

tempnam()The method syntax is as follows:

os.tempnam(dir, prefix)

Parameters

  • dir-- Path of the temporary file to be created.

  • prefix-- Temporary file prefix

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

# File with prefix example
tmpfn = os.tempnam('/tmp/example','example')

print "This is a unique path:"
print tmpfn

The output of executing the above program is:

这是一个唯一路径:
/tmp/example/exampleIbAco8

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions